You need to sign in to do that
Don't have an account?
TheRealist
How to make the triggers fire sequentially?
Hi
lets assume there are multiple triggers on an object like Trig A trig B tric C etc.. how to make them fire in a sequencial order like 1st A should fire then B then C, any sample code would be highly appreciated.
lets assume there are multiple triggers on an object like Trig A trig B tric C etc.. how to make them fire in a sequencial order like 1st A should fire then B then C, any sample code would be highly appreciated.
It is documented in salesforce that if some SObject has more than one trigger we cannot specify the sequence of the trigger. The best practice is write one trigger for a SObject and develop sequences by trigger handler classes. If you need some code example I can help you.
Thanks :)
As a best practise we should only use one trigger per object to avoid these kind of issue...
You can create different methods in one trigger to solve these things by merging them in one trigger..
If all triggers are on different event then there is no issue else it will give you corruption of data...
To avoid these , use Trigger template..trigger and trigger handler
Trigger:
Trigger on conatct(After insert, before insert , after update)
{
create instance of trigger handler..
triggerHandler obj = new triggerHandler ();
obj.onAfterInsert(Trigger.new);
}
Class:
public class mainTriggerclass
{
public void onAfterInsert( list<Contact> lstContact)
{
now from this method you can all all other functionalty sequential to avodi corruption of data...
createAccounts(lstContact); //1st functionality
updateOpportunity(lstContact);//2nd functionality
sendEmailToOthers(lstContact);//3rd functionality
}
}
As I mentioned above , you can haev one trihger per object and then one handler..
Now from the handler class for each event you can create methods and from there you can call all differt methods as epr the sequnec you need them..
Please check and let me know if it helps..
Thanks,
Sandeep
actually im aware of what you guys mentioned but i was particularly asked ,so i just want to know how to work around that.
Thanks :)