Triggers and Order of Execution – Salesforce

When you save a record with an insert, update, or upsert statement, Salesforce performs the following events in order.

Before Salesforce executes these events on the server, the browser runs JavaScript validation if the record contains any dependent picklist fields. The validation limits each dependent picklist field to its available values. No other validation occurs on the client side.

1 – System Validation rule (SV) – Checks for the Required fields and field format like email should in the correct format.

2 – All Before Triggers are executed (BT) – Before trigger will execute and do the manipulation. 

3 – Custom Validation rules are checked (CV) – In this step, Custom validation run and check for the error

4 – Executes duplicate rules (DR) – All duplicate rule will execute for the Object if any

5 – After Triggers are executed (AT) 

6 – Assignment Rules are executed (AR)

7 – Auto-Response Rules are executed (ARR)

8 – Workflow Rules are executed (WR)

If workflow rule update any field then before and after triggers are executed one more time if the workflow rule updates a field (BT & AT)

9 – Process Builder (PB)

If process builder update any field then before and after triggers are executed one more time if the workflow rule updates a field (CV, BT & AT)

       Note: – Custom Validation executes when there is any update is being             made by process builder.

10 – Escalation Rules are executed (ER)

11 – Parent Rollup Summary Formula or Cross Object Formula fields are updated in the respective objects. (RSF, COF and These parent records also goes through the entire execution order)

12 – Grand Parent Rollup Summary and Cross Object Formula Fields Calculation – ( GPRSF, GPCOF, and Grandparent also go through with the same process).

13 – Criteria Based Sharing rules are evaluated (CBS)

14 – Commits the data into Database!

15 – Any Post-Commit Logic is executed (PCL)  (like sending an email)

You can use the below sequence to remember the sequence of the execution and it will help to debug any problem that you will be facing 

SV -> BT -> CV -> DR -> AT -> AR -> ARR -> WR (BT, AT) -> PB(CV, BT, AT)  -> ER -> RSFCOF ->  GP RSFCOF  -> -> CBS -> PCL

Additional Considerations

Please note the following when working with triggers.

The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event. For example, if you have two before insert triggers for Case, and a new Case record is inserted that fires the two triggers, the order in which these triggers fire isn’t guaranteed.

Advertisements

3 thoughts on “Triggers and Order of Execution – Salesforce

  1. Nida Khan May 22, 2019 / 5:11 pm

    Excellent Post!!!

    Like

  2. dave January 29, 2019 / 11:06 pm

    Entitlement Rules?

    Like

    • Amit Singh February 4, 2019 / 7:50 am

      I have no Idea about ET Rules let me check and I will get back to you for the same 🙂

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s