0

I have 2 Afterupdate triggers.

There is Update DML in the first trigger which changes the status from In approvals to Initials Obtained.

There is update DML in the second trigger which updates the Apex sharing when status is Initials Obtained.

The requirement is Whenever status updates to Initials obtained in the first trigger, the second Afterupdate trigger should run and update the Apex sharing for Initials obtained status.

The issue iam facing is with the Order of execution. There are 2 Afterupdate triggers with 2 DMLs inside.

Though the Status is showing as Initials obtained in the Form, the Apex sharing is not showing as that of Initials obtained. Users are facing access issues.

Can you please help me ? Should there be only one Afterupdate trigger with 2 DMLS inside it so that once the first DML is done, system will enter into 2nd DML ?

Thank you


Thank you for the reply. In my requirement i have to update the status first to Initials obtained in a custom object. Then update the Sharing for that object. Only after status change i need to update sharing.

2

You cannot determine which order the individual triggers are executed in. It may differ from time to time.

What you can do is to use one of the trigger patterns. These let's you determine the order of execution and will also solve a few other problem you may run into with complex trigger setups.

The main idea is to have one trigger per object - this trigger starts with a general event handler / dispatcher that is then calling all of the trigger methods that needs to be run on that object.

Hari Krishnan - has developed a great trigger framwork that can be used - An architecture framework to handle triggers in the Force.com platform

Dan Appelman has written the book "Advanced Apex Programming" where he in detail explains the various problems you may run into and is also describing a trigger framwork that can be used to avoid these problems. Advanced Apex Programming

  • Thank you for the reply. In my requirement i have to update the status first to Initials obtained in a custom object. Then update the Sharing for that object. Only after status change i need to update sharing. – Raja May 17 '14 at 7:59
2

Salesforce is not recomonding to have more than one trigger on same object same event. If we have such triggers, we can't predict the order of the execution of them. Here the reference

The order of execution isn’t guaranteed when having multiple triggers for the same object due to the same event. For example, if you have two before insert triggers for Case, and a new Case record is inserted that fires the two triggers, the order in which these triggers fire isn’t guaranteed.

So try to wrap all into one trigger(which are in same event) and apply the logic as per your business requirements. You can use Trigger context variables to manage your code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.