Activity Forums Salesforce Discussions How To Avoid Recursive Trigger in Apex in Salesforce?

  • How To Avoid Recursive Trigger in Apex in Salesforce?

  • Anuj

    Member
    January 14, 2020 at 1:35 pm

    How To Avoid Recursive Trigger in Apex?

  • Ratnesh

    Member
    January 14, 2020 at 2:02 pm

    Recursion occurs when same code is executed again and again. It can lead to infinite loop and which can result to governor limit sometime. To avoid the situation of recursive call, we have to write code in such a way that the trigger will execute one time. To do so, we can create a class with a static Boolean variable with default value true

  • Aditya

    Member
    January 14, 2020 at 3:48 pm

    recursive trigger occurs when code is executed again and again and exceeds CPU time. To avoid it create a class with a static Boolean variable which return true or false value by default it return true value:

    public Class checkRecursive{
    private static boolean run = true;
    public static boolean runOnce(){
    if(run){
    run=false;
    return true;
    }

    else

    {

    return run;

    }
    }

Viewing 1 - 3 of 3 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos