0

When you develop Triggers you can avoid re-entrancy by keeping track of ids in static variables of your Apex Classes, however when dealing with process builders it is not obvious to me how to avoid publishing an event multiple times.

In particular, I have a branch that is executed upon these conditions:

ISNEW() || ISCHANGED([MyCustomObject__c].MyField__c)

What seems to be strange is that in the same transaction ISNEW() this branch is executed four times: one solution would be to avoid re-entrancy for the same record, but I need it for some other branch of the process builder. What is the best practice to avoid "same branch" re-entrancy?

1 Answer 1

3

Try turning off the process builders recursion setting in its advanced options (that is, disabling ‘evaluate a record multiple times in a single save operation’)

Source: https://help.salesforce.com/articleView?id=process_advanced_considerations.htm&type=5&sfdcIFrameOrigin=null If your process uses the ISNEW formula function and reevaluates a record multiple times in a single save operation, the process may execute actions multiple times. For example, your process checks whether an account is created or updated.

Docs example claims “When ISNEW evaluates to true, the process updates the account’s annual revenue and posts to Chatter. When the process updates the account’s annual revenue, the process then reevaluates the record (up to five additional times) because the record was changed. Each time the criteria is evaluated, ISNEW evaluates to true”

6
  • The thing is that I need some branches to be executed as a consequence of other branches. Do I need to split the process builder in 2?
    – Edmondo
    Dec 30, 2020 at 17:40
  • 1
    That might work. Can you build the pb vertically and handle in one? Pbs can also call flows which may give you another palette for logic control Dec 30, 2020 at 19:02
  • i would recommend no more than 1 process builder per object, for execution tidiness. Jan 17, 2021 at 2:34
  • so how do you avoid re-entrancy for some branches like those that emits platform events?
    – Edmondo
    Jan 17, 2021 at 10:26
  • Hmm, maybe multiple pbs are the way you go, setting advanced recursion optioms; or maybe handle for it in the leaf (if the PE was already processed or doesnt need to be, then do-nothing / dont emit the PE again). I am not sure yet so let me know what you try Jan 17, 2021 at 17:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .