2

My basic question is: If I have a flow that updates a Case record based on certain mutually exclusive conditions, is the best practice to have multiple Update Records elements following each other, or to rather use Assignment elements and at the end to do one large update based on all the prior Assignment elements?

Context:

I have a flow that updates custom fields on the Case object, we have moved the logic that we used in a Process Builder over to this flow. We have some custom Date/Time fields that we have created and want them to be populated by the flow, in particular we have a Date/Time Assigned and Date/Time Working. The flow also handles other automation steps for us.

The fields in this example are: Assigned to - the person to work on the Case. Date/Time Assigned - Time at which the Case was assigned. Date/Time Working - Time at which the Case started being worked on.

The idea is if someone starts working on a Case, they should assign the case to their User and change the status of the Case to Working. If the Assigned to is populated, this should populate the Date/Time Assigned with the current time. If the User changes the Status of the Case, the Date Time Working should populate with the current time.

We also have logic that says if the Owner is blank and the Status is changed, then the Owner is populated as the current User.

This means we have a scenario where a User can update the Status of a Case with no Assigned to and this should populate the Assigned to, Date/Time Assigned and Date/Time Working using two separate Update Records elements. This is how it is handled in the flow: Flow1

There are more examples of this in the same flow:

Flow2

Should I replace the Update Records elements with Assignment Elements and have one Update Records element right at the end? I am not sure if processing the Assignment or Update Records elements is faster.

3
  • 5
    Definitely do it all at the end, as a single bulk update. Use assignments to manage your collection of records to update and only assign the fields you really need to update.
    – Phil W
    Jan 26 at 8:29
  • 2
    perform 1 single update, because you must keep in mind that each time you perform an update, it triggers all the record triggered flows for the object + the apex triggers for this object (from your custom code or from managed packages installed) + validation rules etc... and you don't want to have this happening multiple times in your flow.
    – Chris
    Jan 26 at 12:36
  • Thank you guys, I appreciate the input, I'll go ahead and make the changes.
    – Nic
    Jan 27 at 6:04

2 Answers 2

2

If the decisions are mutually exclusive (i.e. only one Update Records path will be taken per transaction), then this design is acceptable. This is because of Flow Bulkification. Multiple records can reach multiple blocking elements (e.g. Update Records) and they will be batched efficiently. However, if it is likely that two or more updates will be met in a single transaction, you should definitely aggregate them together and save the Update Records for the end. This is because Salesforce has Execution Governors and Limits, and repeatedly updating records may run into any of the CPU, DML, SOQL, Email Sends, SOSL, etc limits. You should always strive to be as efficient as possible.

1
  • Thanks very much, I wasn't sure if it had a clever method of batching updates but it makes sense that it would add up.
    – Nic
    Jan 27 at 6:05
0

The update records elements fire individually, so if there are many of them in a row updating the same record it is better to rather use assignment elements to track changes and make one single update.

You must log in to answer this question.

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