Order of execution in Triggers

Order of execution in Triggers



  1. The record is loaded from the database or is initialized in case of an upset statement.
  2. New record’s field values are overwriting the old values, now depending on the origin of the request this flow varies: if the request is from a UI page then the following validations are performed by Salesforce:
    1. Any layout specific rules are checked
    2. All the required values are checked at layout and field level
    3. All the field formats are validated along with the maximum length of field values
If the request originates other than UI then Salesforce only checks for Validation of foreign keys.
  1. Before triggers are executed at the database.
  2. Most of the validations are performed again to verify that all the required fields are holding some values and are not null, at this step user-defined validations are also executed and the only validation which is not repeated in this step are the rules specific to the layout.
  3. After the success of the previous step, the record is reviewed for duplicate records, by running the duplicate rule. If a duplicate is found the flow is stopped and no further actions performed.
  4. In this step, a record is saved to the database but is not committed yet.
  5. All the after Triggers are executed.
  6. In this step, assignment rules are executed.
  7. If there is any auto-response rule is present then they are executed.
  8. Next, in the queues are the workflow, they are executed after the auto-response.
  9. If the workflow was updating a field, then the fields updated in this step and the flow after this step varies if this was the case.
  10. Field was updated then the before and after update triggers are fired once more and standard validation are also executed again. Custom validation escalation rule and duplicate rules are not required to run again.
  11. Once the execution has reached this stage, then the process is fired if there are any declared on the object.
  12. Escalation rules are executed.
  13. Entitlement rules are executed if any.
  14. If there are any roll-up summary field, then they are calculated at this step and the parent object go through the save process.
  15.  sharing rules are executed.
  16. If we reach this stage, then that means no error has occurred and the data is ready to be committed to the database and is committed now.
  17. If there is any post-commit logic like email, then that is executed.

Comments

Popular posts from this blog

If you looking for Salesforce Certified Freelancer for you Salesforce org works feel free to contact us, details are in below:

Visualforce page that shows Contact details using an Extension controller

Trigger Upsert Contact record using trigger when account record is updated