Skip to main content
why static boolean variable for troubleshooting ruccursive triggers,why not constraint?

 
1 resposta
  1. 3 de jun. de 2015, 16:14
    We always used Static Boolean variable to Stop Reccurive Trigger because Static varaible always mantains its state.

    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

    Apex Class with Static Variable

    public class ContactTriggerHandler { public static Boolean isFirstTime = true; }

    Trigger Code

    trigger ContactTriggers on Contact (after update)

    {

        Set<String> accIdSet = new Set<String>(); 

        if(ContactTriggerHandler.isFirstTime)

        {

            ContactTriggerHandler.isFirstTime = false;

             for(Contact conObj : Trigger.New)

      {

                if(conObj.name != 'Test') 

         {

                    accIdSet.add(conObj.accountId);

                }

             }

       // any code here

        }

    }

    http://amitsalesforce.blogspot.in/2015/03/how-to-stop-recursive-trigger-in.html

    Please let us know if this will help you
0/9000