Become an Order of Execution Hero

In this session we will talk talk about Order of Execution in Salesforce. Let see why we need to learn about Order of Execution in Salesforce. Clicks-not-code automations make building applications on the Lightning platform fast and easy. But as your org grows and covers increasingly more business processes, robustness, scale and reliability become your key concerns.

In this session, we will guide you through logic flow, or “Save Order of Execution?, the most important factor in designing sustainable and scalable applications . There’s a lot more to know than ‘triggers run before workflows’. Dig deeper, understand the logic flow and your apps will scale better and run more reliably.

Become an Order of Execution hero and walk away with an understanding of how to design robust apps optimized for scale and how to control recursion and remedy typical problems.

Here is some keynote of session

Order of Execution

Order of Execution
Order of Execution in Salesforce

When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order. Here is a cheat sheet of the Order of execution.

Order of Execution

  1. Loads Initial record.
  2. If the request came from a standard UI edit page, Salesforce runs system validation to check the record for page layout specific rules, field definition, Maximum field length.
  3. Executes  flows that make before-save update. (New Change in Winter 20)
  4. Executes all before triggers
  5. Runs most Custom validation.
  6. Executes duplicate rules
  7. Saves the record to the database, but doesn’t commit yet. 
  8. Executes all after triggers
  9. Executes assignment rules
  10. Executes auto-response rules
  11. Executes workflow rules
  12. If there are workflow field updates, updates the record again.
  13. If workflow field updates introduced new duplicate field values, executes duplicate rules again. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules are not run again.
  14. Executes processes and flow. 
  15. Executes escalation rules
  16. Executes entitlement rules
  17. If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure. 
  18. If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure. 
  19. Executes Criteria Based Sharing evaluation
  20. Commits all DML operations to the database
  21. Executes all after-commit logic, such as sending email.

What is part of the after-commit logic?

  • All email sends
  • Asynchronous Apex: @future methods
  • Async Sharing Rule processing (for >25,000 records)
  • Outbound Messages placed on queue
  • Calculate Index, such as Search Index
  • Render File Previews
  • Publication of Platform Events (if configured)

Lessons learned

  • Check documentation with each release.
    Understand the fine print.
  • Rule of thumb: One trigger, one Process per object.
  • Know how to use the Debug Log (or know someone who knows).
  • Watch out for “***CLOSE TO LIMIT***” debug log entries.
  • Avoid situations that could loop (or know what you are doing).
  • Handle trigger.old with care.
  • Test, test, test – and remember to test with all packages and enough data

Recording

YouTube video

Please note that we have limit of 300 attendees that can join the online sessions. However, recording will be posted on our YouTube channel. Make sure to subscribe our YouTube channel to get notification for video upload.

Bookmarks our “Session in 2020” page for all upcoming and old sessions of 2020. Let us know which topic you want learn next in ApexHours.

Sharing is Caring so Share with your friends Thanks,
Salesforce Apex Hours

Amit Chaudhary
Amit Chaudhary

Amit Chaudhary is Salesforce Application & System Architect and working on Salesforce Platform since 2010. He is Salesforce MVP since 2017 and have 17 Salesforce Certificates.

He is a active blogger and founder of Apex Hours.

Articles: 473

3 Comments

  1. Great overview! I noticed that the Order of Execution of points 13 and 14 have changed with Spring 21 (as per Developer Documentation). Can you explain the logic behind this change?

Leave a Reply

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