0

I'm running into a confusing problem. I've created a flow that automatically updates fields on the child "OrderItem" records underneath a Product2 record.

I run into an apex CPU time limit exceeded error. Okay, so I start reviewing the debug logs. What I find is that somehow, they flow I've created is somehow causing "Order" records to get evaluated with their workflow rules -- we have a lot of rules there, so that times it out.

So I'm trying to find what's causing "Order" records to be evaluated. Problem is, the new flow I've created on "OrderItem" only handles brand-new created fields. (I know that rules without narrow criteria would lead to this issue, but I've already looked through all the rules in debug log and don't see anymore candidates.)

My question is, does updating "OrderItem" records somehow automatically cause "Orders" above them to re-evaluated for workflows? That would be an odd quirk but Salesforce does have quirks.

Otherwise, how can I diagnose how this is happening? I've looked thoroughly and don't see any Workflow Rules, Process Builders, Flows, or Apex Triggers in the debug log that contain DMLs in them on "Order" records -- which, I would expect to find at least one that does, leading to the Order workflows to get evaluated -- but I don't find any.

Note, ultimately this process does cause a rollup field on a custom object looking up to "Order".

If it would help, let me know if you'd like me to attach the debug log for this problem.

CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Order

1 Answer 1

3

Updating an OrderItem automatically causes the implicit Rollup Summary on Order.TotalAmount (i.e. the Sum of OrderItem.TotalPrice)

If you have any other RSF on Order that reference OrderItem children, they will be recalculated in Step 16 of the Triggers and Order of Execution

If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.

In addition, this Order Save Release Update makes this more explicit

To align with Force.com platform requirements, we’re updating the Order Save Behavior feature starting with the Winter ’21 release. This update improves the evaluation of custom application logic on the parent record. Unlike the previous version, the new Order Save Behavior makes Salesforce run custom application logic whenever an order product update causes a change to the parent order. Custom application logic consists of validation rules, Apex triggers, workflow rules, and flows.

N.B. I'm assuming you don't have B2B Commerce Cloud enabled

You must log in to answer this question.

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