We did one session in apex hours of How to become an Order of Execution Hero. In that session we did one deep drive in Salesforce Order of execution and covered some interview question on order of execution. Save Order of Execution is the most important factor in designing sustainable and scalable applications.
When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order. Here is cheat-sheet of Order of execution.
Check this post for more detail Triggers and Order of Execution.
Here is recording of our Apex Hour session.
Thanks,
Amit Chaudhary
When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order. Here is cheat-sheet of Order of execution.
Order of Execution
- Loads Initial record.
- 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.
- Executes flows that make before-save update. (New Change in Winter 20)
- Executes all before triggers.
- Runs most Custom validation.
- Executes duplicate rules.
- Saves the record to the database, but doesn't commit yet.
- Executes all after triggers.
- Executes assignment rules.
- Executes auto-response rules.
- Executes workflow rules.
- If there are workflow field updates, updates the record again.
- 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.
- Executes processes and flow.
- Executes escalation rules.
- Executes entitlement rules.
- 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.
- 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.
- Executes Criteria Based Sharing evaluation.
- Commits all DML operations to the database.
- 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)
Check this post for more detail Triggers and Order of Execution.
How deep is your knowledge of the Order of Execution ?
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.What kind of issues did you experience ?
- Unexpected Outcomes
- Missing or duplicate records
- Blank or “wrongly” populated fields
- Hitting Limits
- CPU Time Limit Exception
- Too many SOQL Queries
Here is recording of our Apex Hour session.
Further Reading:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htmThanks,
Amit Chaudhary
No comments:
Post a Comment