4. Agenda
• Need for Trigger Frameworks
• Design Patterns for Trigger Frameworks
• Benefits for Trigger Frameworks
• Choosing the right Trigger Framework
• Q&A
5. Some Housekeeping Rules…
• Mute your mic
• Keep adding questions in Zoom Q&A Window
• No questions are silly!
• Questions will be answered in the last 15 mins of this session
6. Apex Triggers
• Automatic execution of Apex code responding to Database operations
Insert, Update, Delete, Undelete
Before / After a record save
• Most Standard and All Custom Objects
7. Order of Execution
1. Loads the original record from the database
2. Loads the new record field values from a request and overwrites old values
3. System Validations
4. Custom Validation Rules
5. Before Triggers
6. Duplicate Rules
7. Saves the record to the database but not committed. Record ID is generated
8. After Triggers
9. Assignment Rules execution
10. Auto-response Rules execution
11. Workflow Rules execution
12. Execute Processes
13. Execute Flows
14. Executes Escalation Rules
15. Executes Entitlement Rules
16. Update roll-up summary fields
17. Criteria based sharing evaluation
18. Commits all DML operations to the database
19. Executes post commit logic of sending emails
8. Demo Use Case
Create Task for any Opportunity when it is inserted or updated with
a stage of “Closed Won”.
The Task’s Subject must be set to “Follow Up Test Task”
10. Why Trigger Frameworks?
Inconsistent orchestration for Apex trigger logic
Increased complexity of unit testing
Code maintenance is complex and difficult
Difficult for disparate developers to work together on a single code base
15. Benefits of Trigger Frameworks
Consistent way of writing and executing triggers
Predictable order of execution with a single trigger per object
Prevent recursive trigger execution
Promotes code maintainability and easy unit testing
Cohesive disparate teams with better collaboration
16. Choosing the Right Trigger Framework
Features Trigger Handler Interface Based
Complexity Simple Complex
1 Trigger per sObject *Partially Yes
Extensible No Yes
Code Reusability Low High
Recursion Control No Yes
17. Resources
Lightweight Apex Trigger Framework by Chris Aldridge (Blog)
Minimal SFDC Trigger Framework by Kevin O'Hara (Blog)
Tidy Streamlined Bulkified Triggers (Dev Cookbook)
Trigger Frameworks in Salesforce (YouTube)