Activity Forums Salesforce® Discussions How to avoid recursive trigger in Salesforce?

  • Kirandeep

    Member
    February 12, 2020 at 4:37 pm

    Hi Shubham,

    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

  • Arun

    Member
    February 13, 2020 at 5:53 am

    Hi Shubham,

    Recursion occurs when same code is executed again and again. It can lead to infinite loop and which can result to governor limit sometime. Sometime it can also result in unexpected output or the error “maximum trigger depth exceeded”. So, we should write code in such a way that it does not result to recursion.

    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. In the trigger, before executing the code keep a check that the variable is true or not.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos