Updated March 17, 2023
Introduction to Salesforce Order of Execution
A record’s passage through various procedures and events between SAVE and COMMIT is governed by a set of rules called the “Order of Execution” in Salesforce. In other words, it is the process of recording with an insert, update, or upsert statement making salesforce perform the commands in an orderly format. Salesforce is a CRM (Customer Relationship Management) Software that helps in sales, marketing, and IT teamwork.
- Salesforce Order of execution is simply a process to order the command for recording using an upsert, insert or update statement.
- Ensure you follow the proper steps in an orderly format to run the execution successfully.
- There are two types of triggers in Salesforce order of Execution. One being “after triggers” and the second “before triggers.” They have their functioning depending on what you want to do.
- One thing you can keep in mind is that the execution of a trigger is not sure when various triggers are operating for the same object resulting from the same event. At this point, Trigger Framework comes to use.
How does Salesforce Order of Execution Work?
Salesforce executes the events in an order on their server;
- It initializes the with the upsert statement or loads the original document from the required database.
- From the request raised, it overwrites the old values with the new record filed values.
- Before the record fields are saved, it executes the record-triggered flows.
- It also executes all before triggers.
- Salesforce runs all the validation steps again except the step that enforcement of layout-specific rules.
- It executes the same rules; if a duplicate record is found, it is blocked. And further, after trigger steps are not executed.
- Executes all after triggers, assignment rules, auto-response rules, workflow rules, and escalation rules in the respective order.
- Executes salesforce flow automation such as process, flows launched by these processes and flows launched by the workflow rules.
- After the record field is saved, it executes the record-triggered flows.
- Salesforce executes all the entitlement rules.
- If a record field is related to the cross-object workflow or roll-up summary field, salesforce updates the values in the parent record field of the roll-up summary.
- After the parent record is updated, the same procedure happens for the grandparent field, and the values get updated in the roll-up summary grant parent field.
- All these values get saved and execute the criteria-based sharing evaluation.
- All the DML operations are committed to the database.
- After all the changes are made to the database, it executes the post-commit logic.
Requests sent to Salesforce for Validation
- When salesforce receives a request from the standard UI edit page, validation checks are done based on the specific rules, valid field formats, the maximum length of the field, layout level, and the filed definition level.
- For requests from multiline item creation, the custom validation rules are executed.
- Requests to salesforce are received from other sources such as SOAP API or Apex application; then only foreign keys are validated.
Salesforce Order API Execution
- Regarding API (Application Programming Interface). Salesforce only verifies the foreign keys when the request originates from another source, such as an Apex application or a SOAP API call.
- Salesforce checks that custom foreign keys do not relate to the object before triggering.
- Also, the Forecast Category value should likewise originate from the API call or user interface if you reset Stage to a value supplied in an API request or one that is received from the user interface.
- The Forecast Category defaults to the one associated with the trigger Stage if no value is provided; in this case, the incoming Stage differs from the trigger Stage.
- The Forecast Category does not default when the trigger and arrival stages coincide.
Types of Salesforce Order of Execution
- Before Triggers: “Before Triggers” are the triggers caused before the recorded values are saved to the database.
- After Triggers: Read-only Records are triggered using this.
You can add customized changes to the Salesforce record. This can be done either before or after making changes. Triggers are carried out before or after specific actions like undelete, upsert, etc.
Order of Execution – Saving a Record
The following steps are followed to execute events while saving a record:
- System Validation Rules
- Record Apex “Before Triggers” and Trigger Flow
- Custom Validation Rules
- Duplicate Rule
- Apex “After Triggers”
- Assignment Rules
- Auto-Response Rules
- Workflow Rules
- Escalation Rules
- Bind the summary field
You may run the steps the way you want your process to work.
While understanding the Salesforce Order of Execution, you must know this CRM software. It is not that difficult to understand and execute. This system helps you in various ways, especially in executing what’s right for your business. You can also visit the Salesforce Official Blog Page to understand better. We have pointed out the meaning, types, database system, API, and every aspect you need to know about Salesforce Order of Execution with some takeaways. So, all set to move on with the process?
Frequently Asked Questions
Q1. Can we control the order of execution in workflow in Salesforce?
Answer: The execution of process rules in a particular order is neither supported nor guaranteed by Salesforce. Individual actions and different action categories may not be carried out in a specific order. However, other activities are carried out after field update operations.
Q2. What is the database system’s significance in Salesforce’s execution order?
Answer: Salesforce Order of Execution works by loading the original records from the database. It saves the record to the database and commits all the DML operations (Data Manipulation Language: a simple way to manage the records as it provides easy statements for command executions) to the database.
Q3. Does the validation rule run “before trigger”?
Answer: As mentioned above, in the steps of the order of execution-saving a record, there is a custom validation rule by order of execution. This ensures the process is processed by having the custom validations run after the before triggers.
The above article is a sample of Salesforce Execution Order. You can have a broader perspective on the given topic by referring to these articles.