How the Salesforce order of execution sequences flows, triggers and validation (opens in a new tab)
You will learn the rough sequence in which Salesforce runs Flows, Apex triggers, Validation Rules and after-save automation when a record is saved, and why that order matters when several automations touch the same record.
Why read this
The article is a general overview rather than a detailed reference.
- Initial record submission
- Before-save Record-Triggered Flows
- Before Apex triggers
- Validation and duplicate rules
- Save to database, not yet committed
- After triggers and after-save flows
- Commit and post-commit operations
When a record is created, updated or deleted, Salesforce runs several kinds of automation in a defined sequence. The article says this matters because multiple automations touching the same record can produce unexpected results, repeated updates or errors. Understanding the sequence helps teams troubleshoot and avoid needless complexity.
The process starts with the initial submission, whether from the user interface, the API, Apex, Data Loader or an external application. Before-save Record-Triggered Flows then run before the record is written to the database, and are described as efficient for simple field updates because they avoid an extra save. Before Apex triggers follow, with a short example that sets a default value on a Contact description. Validation Rules and duplicate rules run before the save completes.
Once the record is saved to the database, the transaction is not yet committed, so later errors can still roll the changes back. After triggers and after-save flows then run, handling tasks such as creating related records, sending notifications or starting further processes. The article also notes that legacy workflow, escalation and assignment rules can cause extra updates that re-run parts of the sequence. After a successful transaction, the changes are committed and post-commit work such as Queueable Apex, future methods and scheduled paths can run.
The article closes with common mistakes: several Flows on one object without reviewing their order, duplicating field updates across Flows and Apex triggers, ignoring recursion, and skipping tests for API updates. Its advice is to review existing automation on an object before adding a new Flow, trigger or Validation Rule.
Read the original at dev.to (opens in a new tab)