+ Start a Discussion

Please confirm understanding


I am doing two things to an Opportunity before saving. I have it currently setup as two triggers but I think that this is probably not the best method. Is it normally best to build only one trigger per object that is triggered on a specific event? One trigger for before update, one for before insert, or one for both before update and before insert?

The reason I'm asking is because I am having issues with order of execution. I will probably need to combine the triggers so that they process only as I want and take out any random issues.
There's no defined order for multiple triggers of the same type, so yes, if you have ordering requirements, you should have a single trigger that handles things in the order you want.
Yes Chris:

It is Best to have one trigger per object and use the Trigger.isBefore and Trigger.isAfter to "order" the execution of the trigger.

There is also Trigger.isUpdate and Trigger.isInsert etc...

Check page, 60 of the summer apex guide for the Trigger Context Variables.