+ Start a Discussion

two after insert triggers

Hi All,


 I have two after insert triggers on sameobject.I want to know which one will execute first?




There's no way to know which one will fire first. Execution order is not guaranteed.

If you run your code through the Apex code scanner, it will actually flag this as an issue. You shouldn't have multiple triggers on the same object. Try to combine them.

Anup JadhavAnup Jadhav

Whilst there is no way of determing the order of execution of a trigger on the same object, it is possible to impose the order artificially by following a pattern known as the Trigger pattern.




You'd obviously have to refactor and restructure your code to implement the trigger patter. The advantages outweigh the effort involved in refactoring your code. If you do this correctly, you will be able to reason the trigger control flow, and be confident that it works the way you think it does.