If code block 1 and 2 are in the same synchronous execution context , assuming use of the anti-recursion pattern in knowledge article 000133752 below,
assuming I want both code block 1 and 2 to run just once then would i have to declare a new instance of the public Class checkRecursive? See code comments below.
Article 000133752: https://help.salesforce.com/articleView?id=000133752&language=en_US&type=1
Class code:
public Class checkRecursive{
private static boolean run = true;
public static boolean runOnce(){
if(run){
run=false;
return true;
}else{
return run;
}
}
}
Trigger question:
trigger updateTrigger on anyObject(after update) {
if(checkRecursive.runOnce())
{
//some code block 1
}
if(checkRecursive.runOnce()) //this wont run, right?
{
//some code block 2
}
}
If i want both code block 1 and code block 2 to run just once, would i do this?
trigger updateTrigger on anyObject(after update) {
if(checkRecursive.runOnce())
{
//some code block 1
}
checkRecursive newCheckRecursiveContext = new checkRecursive();
if(newCheckRecursiveContext.runOnce()) //this would run, right?
{
//some code block 2
}
}
if(checkRecursive.runOnce())?