0

I have a process builder which keeps firing on an account object 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? 2. During debugging, i am finding my child account account manager field getting set to null on a condition. I set the debug log level on workflows to finest, and even called an custom apex class. I am still unable to find what component like trigger or workflow rule causes the dml update. Is there any other way to find this on the debug log? Any pointers on this would help.. Buyan

1

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

  • What if the updated child accounts also have children? With your proposal those will not get the update. – Nielsm Aug 25 '16 at 11:50
  • @Marc Zaherscu Thanks for your code. I used the above code and put the validation of runonce on my opportunity insert and update trigger. The issue is that when i create the first opportunity, the trigger executes. Now when i create a second opportunity, the trigger does not fire because the boolean is still false. Now if i understand execution context, should the trigger be fired every time a new opportunity is created or modified? At what point is the execution context created for an object? Is it after every record create or update or is it based on a certain time interval like session? – buyan kumar Aug 29 '16 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.