0

Not a question, but my experiences, from which hopefully someone may learn something.

Salesforce has announced that workflows and processes must eventually be replaced by flows.

Our org has 4 workflows related to OpportunityLineItem that do all kinds of processing with Quantity and UnitPrice. I have created a single before-creation/update flow that captures all functionality of the workflows. I have tested this by first creating Apex unit tests that cover the behavior of the workflows.

Afterwards, I disabled the workflows, enabled the flow and reran the unit tests. Creating unit tests for OpportunityLineItem objects is tricky, by the way, because Quantity, Discount, UnitPrice and TotalPrice are related in sometimes surprising ways.

After a while, all unit tests ran succesfully for the single flow. Also changes via the standard Salesforce UI were handled correctly. But one thing was wrong: when updating an OpportunityLineItem Quantity via a custom-made LWC, the UnitPrice was changed instead of the TotalPrice.

I did not understand this and I could not create a unit test replicating this behavior. What was the problem?

1 Answer 1

0

If you look at Triggers and Order of Execution, you'll see that before-update flows are run in step 3, workflows in step 11 and after-update flows in step 14. Saving the record happens in step 7. So it is not clear whether a workflow should become a before- or after-update flow. But it can be the difference between success and failure.

Changing the before-update flow into an after-update flow solved the problem. All unit tests still run correctly and the LWC now also works properly.

Lesson: be very careful when porting workflows to flows. Create extensive unit tests to help you assess the results. Be extra careful when dealing with OpportunityLineItem objects.

1
  • you should be commended for writing the unit tests before doing the conversion - so rare to see that done
    – cropredy
    May 3, 2022 at 19:20

You must log in to answer this question.

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