function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eran VizelEran Vizel 

Triggers order of execution

Hi,

If I put 2 triggers on same object, and they both set to run on same event (before insert), how can I tell and/or decide which one of them will run first?

Thank you,
Eran
Niket SFNiket SF
Hi Eran,

 There is no any specific assurance that which trigge wil fire first. Its better to to twrite one trigger and call two different handlers which will handle your two different use cases.


 
Shikha AgashiShikha Agashi
Combine both trigger in single Helper Class and define two different method in it. Call this methods in Helper Class as you want to excute the logic.

For example, you have trigger A and Trigger B. If you want to execute first triggerB and then trigger A.

Trigger:
trigger executePattern on Object(Before Insert){ // Mention all the event  

if(Trigger.isInsert&&Trigger.isBefore){
    executePatternHelperClass.BeforeEvent(trigger.New);
}
}

Helper Class:

public class executePatternHelperClass{
public static void BeforeEvent( List<sobject> newMap){
methodB();
methodA();
}

public void methodA(){
   //your logic from triggerA
}
public void methodB(){
   //your logic from Trigger B
}
}
Eran VizelEran Vizel
Got ya,

Thank you for your replies!