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
- https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm
- https://trailhead.salesforce.com/content/learn/modules/apex_triggers
- https://trailhead.salesforce.com/content/learn/projects/quick-start-apex-coding-for-admins/create-a-trigger
- https://trailhead.salesforce.com/content/learn/modules/apex_testing/apex_testing_triggers
- https://trailhead.salesforce.com/content/learn/modules/apex_triggers/apex_triggers_bulk
- https://www.pantherschools.com/category/developer/
