Sometimes we face the problem of recursive trigger. The solution of this problem is:
You can create a class with a static Boolean variable with default value true.
In the trigger, before executing your code keep a check that the variable is true or not.
Once you check Update the variable value false.
Apex Class with Static Variable
public class TriggerHandler
{
public static Boolean isFirstTimeTriggerCalled = true;
}
Trigger Code
trigger AccountTrigger on Account (after update)
{
Set<String> accIdSet = new Set<String>();
if(TriggerHandler.isFirstTimeTriggerCalled)
{
TriggerHandler.isFirstTimeTriggerCalled = false;
//Any Code Here
}
}
Leave a comment