• #19409
    Salesforce | Manpreet Manpreet #229
    Forcetalks

    How to avoid recursive trigger calls?

    Ineed to stop the recursive behaviour of trigger calls?

     

    #19414
    Salesforce | Suraj Suraj #168
    Forcetalks

    Hi Manpreet,

    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.

     

    #41383
    Forcetalks

    Hello,

    To avoid recursive triggers 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.

     

    #41384
    Forcetalks

    Here is the code-

    Apex class:-

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

    Trigger-

    trigger updateTrigger on anyObject(after update) {
    if(checkRecursive.runOnce())
    {
    //write your code here
    }
    }

    Thanks.

Viewing 4 posts - 1 through 4 (of 4 total)

Please to reply to this topic.

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 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?