• #66866
    Salesforce | Anuj Anuj #8
    Forcetalks

    How To Avoid Recursive Trigger in Apex in Salesforce?

    How To Avoid Recursive Trigger in Apex?

     

    #66869
    Salesforce | Ratnesh Ratnesh #9
    Forcetalks

    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

    #66874
    Salesforce | Aditya Aditya #15
    Forcetalks

    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 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

Popular Salesforce Videos

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?