So I like many of you am using the static variable "trick" to prevent recursion in my triggers.
But I have one object with many triggers on it all of which are using the method outlined here
https://help.salesforce.com/apex/HTViewSolution?id=000133752&language=en_US
My question is, is it true that it two triggers fire in the same execution and use the same check, will they share the same static variable values and therefore the execution of the first trigger will prevent the execution of the second one?
Best Answer
The problem is that your variables are
static
. Remove the keywordstatic
and they'll become instance variables and will only apply within the context of each instance of the trigger.I don't know exactly what pattern you're using, but if all you're doing is calling a single class, use something more like the following:
Remember that when you do the check
if(!TriggerHelper.isReEnterInsrt)
all you're doing is testing to see whether or not it's been initialized in your class. You don't need to change it's value. Instead, all you need do is declare a new instance of it by callingTriggerHelper.isReInsert isReInsert = new TriggerHelper.isReEnterInsrt;