Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Episode 20 - Trigger Frameworks in Salesforce

562 views

Published on

What are different types of framework for writing triggers in Apex

Published in: Education
  • Be the first to comment

  • Be the first to like this

Episode 20 - Trigger Frameworks in Salesforce

  1. 1. Path to Code Begin Your Salesforce Coding Adventure
  2. 2. Episode 20 Trigger Frameworks in Salesforce
  3. 3. • Enterprise Solutions Architect • Global Community Speaker Jigar Shah @jigarshah189
  4. 4. Agenda • Need for Trigger Frameworks • Design Patterns for Trigger Frameworks • Benefits for Trigger Frameworks • Choosing the right Trigger Framework • Q&A
  5. 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. 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. 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. 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”
  9. 9. Demo 1 Triggers with Business Logic
  10. 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
  11. 11. Trigger Handler Pattern sObject <sObject>Trigger <sObject>TriggerHandler Business Logic 1 Business Logic N One Trigger per sObject Delegator
  12. 12. Demo 2 Trigger Handler Framework
  13. 13. Interface based Trigger Framework sObject <sObject>Trigger <sObject>TriggerHandler Business Logic ITriggerHandler TriggerDispatcher run (ITriggerHandler handler) implements Interface calls calls Dynamic Binding
  14. 14. Demo 3 Interface based Trigger Framework
  15. 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. 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. 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)
  18. 18. Trailhead Modules Apex Triggers
  19. 19. Q & A
  20. 20. Thank You
  21. 21. Subscribe

×