Search
  • KrazyTech Team

Become a Salesforce Order of Execution Hero

Order of execution in Salesforce is important to understand if you are an Salesforce Admin who works on automating processes or if you are a developer that writes trigger code.

In this post we will talk about how to become an Order of execution Hero!


What is Order of Execution in Salesforce

Order of execution is a set of rules that describe the path a record takes through all automations and the events that happen when you save a record with an insert, update, or upsert statement.

Check out this ApexHours session on “Become an Order of Execution hero” to understand how to design robust apps, optimized for scale, and how to control typical recursion and remedy problems.

Many people struggle to remember the order of execution which starts with a DML (insert, update or delete). The diagram below provides a nice visual reference.



Source: Daniel Stange and Marc B Kirsch

Order of Execution

When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in this order:

  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, and maximum field length.

  3. Executes flows that make a “before-save” update (new change in Winter 20).

  4. Executes all before triggers.

  5. Runs most custom validation rules.

  6. Executes duplicate rules.

  7. Saves the record to the database, but doesn’t commit yet.

  8. Executes all after triggers.

  9. Assignment rules.

  10. Executes auto-response rules.

  11. Executes workflow rules.

  12. If there are workflow field updates, then it updates the record again.

  13. If the Workflow field updates introduced new duplicate field values, executes duplicate rules again.

  14. If the record was updated with workflow field updates, it fires before and after update triggers one more time (and only one more time) in addition to standard validation.

  15. Custom validation rules are not run again.

  16. Executes processes and flow.

  17. Escalation rules.

  18. Executes entitlement rules.

  19. Executes record-triggered flows that are configured to run after the record is saved.

  20. 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.

  21. 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.

  22. Executes Criteria Based Sharing evaluation.

  23. Commits all DML operations to the database.

  24. Executes all after-commit logic, such as sending email.

Post Source Link

1 view0 comments