Activity Forums Salesforce® Discussions What will happen if trigger which causes a workflow rule to fire and then goes in a loop. Will it terminate after some update or events ?

  • Gourav

    Member
    August 26, 2016 at 10:06 am

    Hi Mohit,

    One workaround is to set a private static variable in a global class so it works as a flag, not avoiding the trigger fires twice instead it avoids overpassing the limits.

     

    Something like this. Create a Validator Class:

     

    global class Validator_cls{ private static boolean blnAlreadyDone = false; public static boolean hasAlreadyDone(){ return blnAlreadyDone; }

     

    public static void setAlreadyDone() {

    blnAlreadyDone = true;
    } }

     

    In the trigger include a line like this one:

    trigger OpportunityTrigger_tgr on Opportunity (before insert, before update) { if(!Validator_cls.hasAlreadyDone()){ // Your trigger code here Validator_cls.setAlreadyDone(); } }

     

    So, when the trigger is fired by the first time it sets the flag in true and at the second time it won't pass again over the executed code.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos