Print this page

Avoiding Recursive Trigger Calls

Knowledge Article Number 000133752
Description Many developers face this issue because of a recursive trigger. For example, in an 'after update' trigger, a developer could be performing an update operation and this would lead to recursive call, and the error:
"maximum trigger depth exceeded"
Resolution In order to avoid the situation of recursive call, make sure your trigger is getting executed only one time. To do so, 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, make the variable false.

Class code :
public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
     return true;
        return run;

Trigger code :
trigger updateTrigger on anyObject(after update) {

    //write your code here            



promote demote