Can anyone explain me how to stop recursive triggers with an example?
1 Answer
First of all you have to make sure that your trigger is executed just one time. For doing this, you have to make one class and add static boolean variable with default value true in it.
In the trigger, before executing your code keep a check that the variable is true or not.
Once you check make the variable false.
Following is the code for that.
Class Code :
public Class checkRecursive{ private static boolean check = true; public static boolean checkOneTime(){ if(check){ check = false; return true; } else{ return check; } } } Trigger :
trigger testTrigger on sObject(after update){ if(checkRecursive.checkOneTime()){ // Write Trigger Code/logic here } } I hope this will help you.!!!