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

More Related Content

PDF
Apex trigger framework Salesforce #ApexTrigger #Salesforce #SFDCPanther
PPTX
Salesforce Development Best Practices
PPTX
Introduction to Apex for Developers
PPTX
Episode 19 - Asynchronous Apex - Batch apex & schedulers
PDF
Replicate Salesforce Data in Real Time with Change Data Capture
PDF
Introduction to Apex Triggers
PDF
Best Practices with Apex in 2022.pdf
PDF
Decluttering your Salesfroce org
Apex trigger framework Salesforce #ApexTrigger #Salesforce #SFDCPanther
Salesforce Development Best Practices
Introduction to Apex for Developers
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Replicate Salesforce Data in Real Time with Change Data Capture
Introduction to Apex Triggers
Best Practices with Apex in 2022.pdf
Decluttering your Salesfroce org

What's hot (20)

PPTX
Integrating with salesforce using platform events
PPTX
Salesforce Overview For Beginners/Students
PPTX
Salesforce Sharing Architecture
PPTX
Salesforce Integration Pattern Overview
PDF
Salesforce overview
PDF
Introduction to Salesforce | Salesforce Tutorial for Beginners | Salesforce T...
PPTX
Salesforce administrator training presentation slides
PPTX
Commerce Cloud 101
PDF
Manage Salesforce Like a Pro with Governance
PPTX
Salesforce intro session_for_students_v2
PPTX
Salesforce integration best practices columbus meetup
PPT
Salesforce Integration
PDF
Lwc presentation
PDF
Two-Way Integration with Writable External Objects
PPTX
Introduction to lightning Web Component
PPT
Salesforce complete overview
PDF
Lightning web components - Episode 1 - An Introduction
PDF
Apex Testing Best Practices
PDF
A Comprehensive Guide to Salesforce Field Service
PPTX
Data model in salesforce
Integrating with salesforce using platform events
Salesforce Overview For Beginners/Students
Salesforce Sharing Architecture
Salesforce Integration Pattern Overview
Salesforce overview
Introduction to Salesforce | Salesforce Tutorial for Beginners | Salesforce T...
Salesforce administrator training presentation slides
Commerce Cloud 101
Manage Salesforce Like a Pro with Governance
Salesforce intro session_for_students_v2
Salesforce integration best practices columbus meetup
Salesforce Integration
Lwc presentation
Two-Way Integration with Writable External Objects
Introduction to lightning Web Component
Salesforce complete overview
Lightning web components - Episode 1 - An Introduction
Apex Testing Best Practices
A Comprehensive Guide to Salesforce Field Service
Data model in salesforce
Ad

Similar to Episode 20 - Trigger Frameworks in Salesforce (20)

PPTX
Episode 13 - Advanced Apex Triggers
PPTX
Episode 5 - Writing unit tests in Salesforce
PPTX
Microsoft Fakes, Unit Testing the (almost) Untestable Code
PPTX
Unit Tests with Microsoft Fakes
PPTX
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
PDF
Sista: Improving Cog’s JIT performance
PPTX
Build Great Triggers Quickly with STP (the Simple Trigger Pattern)
PDF
Continuous Delivery: How RightScale Releases Weekly
PPTX
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
PDF
What is this agile thing anyway
PPTX
NET Code Testing
PPTX
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
PPT
Stopping the Rot - Putting Legacy C++ Under Test
PPTX
Binary Studio Academy: .NET Code Testing
PDF
Testing Angular
PPTX
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
PPTX
Continuous Delivery - Automate & Build Better Software with Travis CI
PPTX
Silicon Valley JUG - How to generate customized java 8 code from your database
PPTX
How to generate customized java 8 code from your database
PDF
End-end tests as first class citizens - SeleniumConf 2020
Episode 13 - Advanced Apex Triggers
Episode 5 - Writing unit tests in Salesforce
Microsoft Fakes, Unit Testing the (almost) Untestable Code
Unit Tests with Microsoft Fakes
GlobalLogic Test Automation Online TechTalk “Test Driven Development as a Per...
Sista: Improving Cog’s JIT performance
Build Great Triggers Quickly with STP (the Simple Trigger Pattern)
Continuous Delivery: How RightScale Releases Weekly
BTD2015 - Your Place In DevTOps is Finding Solutions - Not Just Bugs!
What is this agile thing anyway
NET Code Testing
JavaOne 2016 - CON3080 - Testing Java Web Applications with Selenium: A Cookbook
Stopping the Rot - Putting Legacy C++ Under Test
Binary Studio Academy: .NET Code Testing
Testing Angular
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Continuous Delivery - Automate & Build Better Software with Travis CI
Silicon Valley JUG - How to generate customized java 8 code from your database
How to generate customized java 8 code from your database
End-end tests as first class citizens - SeleniumConf 2020
Ad

More from Jitendra Zaa (20)

PPTX
Episode 18 - Asynchronous Apex
PPTX
Episode 15 - Basics of Javascript
PPTX
Episode 23 - Design Pattern 3
PPTX
Episode 24 - Live Q&A for getting started with Salesforce
PPTX
Episode 22 - Design Pattern 2
PPTX
Episode 21 - Design Pattern 1
PPTX
Episode 17 - Handling Events in Lightning Web Component
PPTX
Episode 16 - Introduction to LWC
PPTX
Introduction to mulesoft - Alpharetta Developer Group Meet
PPTX
Episode 12 - Basics of Trigger
PPTX
Episode 11 building & exposing rest api in salesforce v1.0
PPTX
Episode 10 - External Services in Salesforce
PPTX
Episode 14 - Basics of HTML for Salesforce
PPTX
South East Dreamin 2019
PPTX
Episode 9 - Building soap integrations in salesforce
PPTX
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
PPTX
Episode 6 - DML, Transaction and Error handling in Salesforce
PPTX
Lightning Web Component in Salesforce
PPTX
Episode 4 - Introduction to SOQL in Salesforce
PPTX
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces
Episode 18 - Asynchronous Apex
Episode 15 - Basics of Javascript
Episode 23 - Design Pattern 3
Episode 24 - Live Q&A for getting started with Salesforce
Episode 22 - Design Pattern 2
Episode 21 - Design Pattern 1
Episode 17 - Handling Events in Lightning Web Component
Episode 16 - Introduction to LWC
Introduction to mulesoft - Alpharetta Developer Group Meet
Episode 12 - Basics of Trigger
Episode 11 building & exposing rest api in salesforce v1.0
Episode 10 - External Services in Salesforce
Episode 14 - Basics of HTML for Salesforce
South East Dreamin 2019
Episode 9 - Building soap integrations in salesforce
Episode 8 - Path To Code - Integrate Salesforce with external system using R...
Episode 6 - DML, Transaction and Error handling in Salesforce
Lightning Web Component in Salesforce
Episode 4 - Introduction to SOQL in Salesforce
Episode 3 – Classes, Inheritance, Abstract Class, and Interfaces

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Pre independence Education in Inndia.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
GDM (1) (1).pptx small presentation for students
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
RMMM.pdf make it easy to upload and study
PPTX
master seminar digital applications in india
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Pre independence Education in Inndia.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Cell Types and Its function , kingdom of life
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
O7-L3 Supply Chain Operations - ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
VCE English Exam - Section C Student Revision Booklet
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Institutional Correction lecture only . . .
PPH.pptx obstetrics and gynecology in nursing
GDM (1) (1).pptx small presentation for students
01-Introduction-to-Information-Management.pdf
Pharma ospi slides which help in ospi learning
RMMM.pdf make it easy to upload and study
master seminar digital applications in india

Episode 20 - Trigger Frameworks in Salesforce

  • 1. Path to Code Begin Your Salesforce Coding Adventure
  • 3. • Enterprise Solutions Architect • Global Community Speaker Jigar Shah @jigarshah189
  • 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”
  • 9. Demo 1 Triggers with Business Logic
  • 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. Trigger Handler Pattern sObject <sObject>Trigger <sObject>TriggerHandler Business Logic 1 Business Logic N One Trigger per sObject Delegator
  • 13. Interface based Trigger Framework sObject <sObject>Trigger <sObject>TriggerHandler Business Logic ITriggerHandler TriggerDispatcher run (ITriggerHandler handler) implements Interface calls calls Dynamic Binding
  • 14. Demo 3 Interface based Trigger Framework
  • 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)
  • 19. Q & A