2

We automatically create an Opportunity when an Account is created as part of an after-insert Trigger on Account.

This all occurs in the after insert Account transaction, there are no @future or queueables involved.

Some of the fields that are set on the Opportunity as part of this are prone to frequent updates, so we moved that logic into a Process Builder. This PB is set to fire on create of Opportunity with no filter logic.

PB Fires on Opp Insert

PB has no criteria

We have observed that when an Opportunity is created manually, the PB fires with no problem. However, when an Account is created and the Opportunities are created by the trigger (DML insert), the PB does not fire.

The PB is set to allow recursion.

So: is this by design? Any way to get the PB to fire on a DML-inserted record?

6
  • 1
    have you looked at the debug logs for the apex use case?
    – cropredy
    May 9 '19 at 20:57
  • 1
    Just for debugging purposes and a sanity check, I would adjust the setting to Start the process "when a record is created or edited" just to see if the PB runs in that situation. Shouldn't make a difference on the surface, but I've seen stranger things :-) May 9 '19 at 21:24
  • Thank you both for the suggestions. @cropredy - there is no evidence in the log that the PB is firing (looked for a WF_CRITERIA_BEGIN line with the name of the PB); @Brian Miller - I tried setting the PB to fire on create and edit and changing the criteria node to contain ISNEW() only; this didn't work either. Thanks again. May 13 '19 at 15:15
  • Does the debug log when you create an Account actually show Opportunity DML?
    – cropredy
    May 13 '19 at 15:18
  • Per automation best practices, 1. Have only one record-change process per object 2.For each object, use one automation tool. So your issue could have been avoided if you followed any of the above.
    – Has Nah
    Dec 22 '20 at 4:04
1

The problem turned out to be related to order of execution.

The logic of the Process Builder (not the entry criteria, the body of the process) depended on a field, Prior_Currency__c, on the parent Account of the Opportunity. Prior_Currency__c is being set by PB on Account create.

So when the Opportunity was created manually, the PB was looking back onto the Account and Prior_Currency__c was properly populated, and the business logic worked to set the field on the Opportunity.

enter image description here

However, when the Account was created, it spawned Opportunities at that time via the trigger code. According to order of execution, the PB on the Opportunity then ran, then the PB on the to decide what to populate onto the Opportunity. The Opp PB was running before the data it needed was set.

Opp PB Fires Before Required Data is Set

So the bottom line is that the PB's were running properly but due to order of execution it did not have the correct data to set the field properly.

2
  • 1
    good job diagnosing; the debug log should have been you clue to this -- PBs aren't "batched up" after all apex DML, they occur immediately after the target record's DML
    – cropredy
    May 13 '19 at 20:48
  • Thank you, as I noted previously there was no evidence the PB was firing from the logs. Not sure what I missed there - I was seeing WF_CRITERIA_BEGIN messages so it wasn't the log level. May 14 '19 at 16:35

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.