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
sai.sfsai.sf 

two after insert triggers

Hi All,

 

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

 

Thanks

craigmhcraigmh

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.

 

http://developer.force.com/cookbook/recipe/trigger-pattern-for-tidy-streamlined-bulkified-triggers

 

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.