Prevent Recursive Trigger in Salesforce Apex

What is recursive trigger?

You have learned about recursion process of loop. Same logic here means a trigger fire by itself. In detail you say that recursive trigger fire by some code of block which is written in same apex trigger or INSERT or UPDATE.

public Class AvoidRecursive
{
    private static boolean isRun = true;
    public static boolean runOnce()
    {
        if(isRun)
        {
            isRun=false;
            return true;
        }
        else
        {
           return isRun;
        }
    }
}

Use above runOnce() static method in trigger before insert/update statement like

if(AvoidRecursive.runOnce())
{
     // Database insert/update/delete statement
}

Leave a Reply

Your email address will not be published. Required fields are marked *