SALESFORCE ORDER OF EXECUTION
Understanding the complete transaction lifecycle
Step 1
Retrieve or Initialize Record
Load record from database or initialize new record with default values from object definition.
Step 2
Overwrite Existing Field Values
System overwrites old values with values submitted in the request (from UI, API, or code).
Step 3
Run Before-Save Flows
Execute record-triggered flows configured to run "before save". Can modify field values without DML.
Step 4
Execute Before Triggers
Run all before insert/update triggers. Can modify record fields before they're saved to database.
Step 5
Perform System Validation
Validate required fields, field formats, length limits, and standard picklist values. Throws error if validation fails.
Step 6
Check for Duplicate Rules
Run duplicate rules to identify potential duplicate records. Can block save or alert user based on configuration.
Step 7
Save Record to Database
Commit record to database but don't commit transaction yet. Record gets an ID if new insert.
Step 8
Execute After Triggers
Run all after insert/update triggers. Record is read-only; use for creating related records or callouts.
Step 9
Apply Assignment Rules
Execute assignment rules for Cases and Leads to assign owner based on criteria.
Step 10
Trigger Auto-Response Rules
Send auto-response emails for Cases and Leads if configured.
Step 11
Execute Workflow Rules
Evaluate and execute workflow rules. Can trigger field updates, which may cause re-evaluation.
Step 12
Run Escalation Rules
Execute escalation rules for Cases to escalate based on time and criteria.
Step 13
Execute Salesforce Flow Automation
Run record-triggered flows configured as "after save". Can perform DML operations and callouts.
Step 14
Run After-Save Record-Triggered Flows
Execute flows that run after record is saved. Used for asynchronous operations.
Step 15
Apply Entitlement Rules
Execute entitlement processes for Cases to track service level agreements (SLAs).
Step 16
Update Roll-Up Summary Fields
If record has roll-up summary fields, update parent records. May trigger parent record's order of execution.
Step 17
Check for Grandparent Record Update
If parent record updated, check if grandparent has roll-up summary fields and update recursively.
Step 18
Reevaluate Criteria-Based Sharing
Recalculate sharing rules if record criteria changed. Updates sharing tables.
Step 19
Commit All DML Operations to Database
Transaction commits. All changes become permanent. If any error occurs before this, entire transaction rolls back.
Step 20
Execute Post-Commit Logic
Run asynchronous operations: email sends, Platform Events, async Apex (@future, Queueable), outbound messages.
Initialization
Before Save
Validation
Database Save
After Save
Commit
Post-Commit
⚠️ Critical Points
• Before triggers run before validation: They can modify field values, but system validation happens after.
• After triggers see read-only records: Cannot modify the triggering record directly.
• Workflow field updates cause re-evaluation: Steps 5-18 can repeat if workflow updates fields.
• Roll-up summary updates cascade: Child record save can trigger parent's full order of execution.
• Everything before Step 19 is in one transaction: Any error rolls back the entire operation.
• Post-commit logic runs asynchronously: Cannot roll back if this fails.
• After triggers see read-only records: Cannot modify the triggering record directly.
• Workflow field updates cause re-evaluation: Steps 5-18 can repeat if workflow updates fields.
• Roll-up summary updates cascade: Child record save can trigger parent's full order of execution.
• Everything before Step 19 is in one transaction: Any error rolls back the entire operation.
• Post-commit logic runs asynchronously: Cannot roll back if this fails.