Create a Rollup-Summary trigger in Salesforce?

Table of Contents

Prerequisite

Create a Custom Field on the Account Object “Number of Contacts” with a Number Data Type that does not have any decimal point in it.

Introduction to Apex Trigger Scenario

Requirement (Roll-up Summary Trigger)
Develop a Solution that will count the related contact related to the Account and store the information in the “Number of Contacts” field.

Note:- The contact can be created/deleted/undeleted and updated from the Account Record. So please keep that in mind

Questions to be asked

Question?

  • Which Object
    • Contact
  • Events
    • after insert, after delete, after undelete, after update
  • Functionality
    • Develop a Solution that will count the related contact related to the Account and store the information in the “Number of Contacts” field.

Hands-On

Apex Trigger


					
				

Dispatcher Class


					
				

Handler Class


					
				

Helper Class


					
				

Watch Complete Video

Assignments

→ Apex Trigger 10

Prerequisite
Create the Custom Fields on the Account Object “Sum of Closed Opportunity Amount” & “Sum of Open Opportunity Amount” with a Currency Data Type with 2 Decimal Points.

Requirement (Rollup Summary Trigger)
Develop an Apex trigger to SUM the Opportunity Amount of the Closed Opportunity and Open Opportunities. The closed opportunities are the ones with the Status equal to “Closed Won” OR “Closed Lost”. And store the result in the “Sum of Closed Opportunity Amount” & “Sum of Open Opportunity Amount” fields respectively in the related Account for the opportunity.

Note:- The Opportunity can be created/deleted/undeleted and updated from the Account Record. So please keep that in mind

Scenarios for Update DML

  • The account has been changed
  • The amount has been changed

Resources

Amit Singh
Amit Singh

Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion

Articles: 299

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading