Activity Forums Salesforce® Discussions How can we avoid the trigger from firing by a process builder?

  • How can we avoid the trigger from firing by a process builder?

    Posted by Mohit on August 25, 2016 at 2:51 pm

    Hi All,

    How can we avoid the trigger  from firing by a process builder?

    I have a scenario in which I have a process builder which keeps firing on an sobject when it is created or modified. The logic is that it look at the parent account field and if a custom field called account manager which is a lookup to the user is changed or modified, it calls a flow. The flow then loops through all children of the parent and updates the child account account manager field based on parent. Here is my question. 1. Because my the updates to the account by my process builder/flow combination, it fires some after update triggers on the account which keep calling the pb/flow again.So How do i prevent my process builder not to fire my triggers again?

    Please give suggestion

    Gourav replied 6 years, 1 month ago 2 Members · 1 Reply
  • 1 Reply
  • Gourav

    Member
    August 26, 2016 at 8:28 am

    From what it seems you are dealing with a recursion problem here. The most obvious solution I can think of is using some custom settings or using a helper class that would enable the execution of the trigger one time and that would become inactive after the execution.

    This would guarantee that your trigger is only being executed once.

    This is an example of a helper class

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

    And this is in action

    trigger updateTrigger on anyObject(after update) {

    if(checkRecursive.runOnce())
    {
    //write your code here
    }

    }

     

    The above example was taken from here : link

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos