+ Start a Discussion
HelloSanHelloSan 

Opportunity object has Two triggers say A and B with different Events i.e A(before insert,before update) and B(after insert,after update) when trigger A is invoked which inturn invoking another trigger B how can we stop this

David Holland 6David Holland 6
HelloSan

Is there a reason you wouldn't want the second trigger firing, or why you have two separate triggers?

Struggling to understand the user case?

Many thanks
Ken KoellnerKen Koellner
I've had some scenerio where the functionality of one trigger has to defeat the other.  Of course if the before trigger prevented the after trigger from functioning all the time then there would be no reason have the after trigger at all.

First, I would encourage you to put minimal logic in your trigger and class methods in utility apex classes.  pass in the trigger stuff you neet like Trigger.newList and Trigger.oldMap and make no reference to the Trigger namespace in the apex class.  That keeps your code clean.

Then let's say when the before trigger does certain things, you want to disable the after trigger.  In the util class, say it is named OppTriggerUtils, called by the after trigger you could have a variable like "static boolean disableAfter = false".  Then in your processing method for after logic, if disableAfter is true return without doing in anything.  In your before trigger method, if you want the after trigger disabled, you could code OppTriggerUtils.disableAfter = true.

We have some triggers where object A updated object B and object B updates object A.  But if they both fired, it would be a loop.  So the A trigger disables the B trigger and the B trigger disables the A trigger.

Since are you statics exists for the duration of a request (and only the duration of the request), you can use them to communicate between trigger modules.
HelloSanHelloSan
Hi Ken thanks for your response,please send some sample code for the defined scenario.