DEV Community

Neha
Neha

Posted on

Salesforce Order of Execution: 9 Important Steps Every Admin and Developer Should Understand

When a user creates or updates a record in Salesforce, several processes may run behind the scenes. These include validation rules, flows, Apex triggers, duplicate rules, and other automation.

Understanding the Salesforce Order of Execution helps administrators and developers identify why automation runs in a particular order and how different processes affect each other.

If multiple automations update the same record, an incorrect design can lead to unexpected results, repeated updates, or errors. Knowing the execution sequence makes it easier to build reliable Salesforce applications.

  1. What Is Salesforce Order of Execution?

Salesforce Order of Execution is the sequence of steps Salesforce follows when a record is created, updated, or deleted.

For example, when a sales representative updates an Opportunity, Salesforce may execute validation rules, before-save flows, Apex triggers, after-save flows, and other automation.

These processes do not run randomly. Salesforce follows a defined execution sequence.

Understanding this sequence helps teams troubleshoot automation problems and avoid unnecessary complexity.

  1. Initial Record Submission

The process starts when a user or system submits a record for creation or update.

The request may come from:

Salesforce user interface

REST or SOAP API

Apex code

Data Loader

An external application

Salesforce begins processing the submitted record and prepares it for database operations.

  1. Before-Save Record-Triggered Flows

Before-save record-triggered flows run before the record is saved to the database.

They are useful when you need to update fields on the same record.

For example, when a Lead's phone number is entered, a before-save flow can format or update another field before the record is saved.

These flows are generally efficient for simple field updates because they avoid an additional save operation.

  1. Before Triggers

After the before-save flow stage, Salesforce executes before Apex triggers.

Before triggers allow developers to modify field values before the record is committed to the database.

A simple example is setting a default value:

trigger ContactBeforeTrigger on Contact (before insert) {
for (Contact con : Trigger.new) {
if (String.isBlank(con.Description)) {
con.Description = 'New Contact';
}
}
}

This approach is useful when the required logic is better handled through Apex.

  1. Validation Rules and Duplicate Rules

Salesforce performs validation checks before completing the save.

Validation rules check whether the record meets defined business conditions.

For example, a company may require an email address before allowing a Contact record to be saved.

Duplicate rules can also identify records that may already exist in Salesforce.

These checks help maintain data quality and reduce duplicate entries.

  1. Record Saved but Not Yet Committed

After the relevant validation and before-save processing, Salesforce saves the record to the database, but the transaction has not yet been committed.

This distinction is important.

The record has reached the database save stage, but other automation and processing steps may still run. If an error occurs later in the transaction, Salesforce can roll back the changes.

  1. After Triggers and After-Save Flows

After triggers run after the record has been saved to the database.

They are useful when developers need access to record IDs or want to perform related-record operations.

After-save record-triggered flows can also perform actions such as:

Creating related records

Updating other records

Sending notifications

Starting additional business processes

For example, when an Opportunity is marked as Closed Won, an after-save flow can create a follow-up task for the account manager.

  1. Workflow, Processes, and Other Automation

Salesforce can also execute additional automation and system processes during the transaction.

Depending on the configuration and type of operation, these may include workflow-related actions, escalation rules, assignment rules, and other platform processing.

Some legacy automation can cause additional updates to records and may lead to parts of the execution sequence running again.

For this reason, administrators should review older automation when troubleshooting unexpected record updates.

  1. Commit and Post-Commit Operations

If the transaction completes successfully, Salesforce commits the changes.

Post-commit operations can then run. These may include asynchronous processing, sending email, and other operations that happen after the main transaction is committed.

Examples of asynchronous processing include Queueable Apex, future methods, and scheduled paths in record-triggered flows.

These processes are useful when work does not need to finish within the original transaction.

Common Mistakes to Avoid

Even experienced Salesforce teams can face problems when multiple automation tools are used without a clear structure.

Some common mistakes include:

Creating multiple flows for the same object without reviewing their order.

Using Apex triggers and flows to perform the same field updates.

Ignoring recursion caused by repeated record updates.

Forgetting to test automation when records are updated through APIs.

Using asynchronous processing when the operation must finish immediately.

A clear automation strategy makes Salesforce easier to maintain and troubleshoot.

Final Thoughts

Salesforce Order of Execution is an important concept for anyone working with Salesforce administration or development. It explains how the platform processes records and how different automation tools interact.

Before creating a new flow, trigger, or validation rule, review the existing automation on that object. A well-planned execution strategy can reduce errors and make business processes more reliable.

For organizations that need help designing, managing, or improving their Salesforce environment, iBirds Software Services provides Salesforce-focused technology and consulting services.

Top comments (0)