Apex Aide apexaide

Another flow trick: The assignment step

thegoodenoughconsultant.com· ·Intermediate ·Admin ·1 min read
Summary

This insight reveals a useful optimization in Salesforce Flow: you can combine setting field values on a single record variable and adding that record to a collection variable into one assignment step as long as adding to the collection is last. This reduces the number of assignment steps inside loops, which simplifies flow design and can improve readability. Salesforce professionals working with Flows can use this to streamline collection-building processes before performing DML operations on bulk records. Remember, the order of assignments in a flow step is crucial to ensure correct behavior.

Takeaways
  • Merge field assignments and adding to collection into one assignment step.
  • Ensure adding the record to the collection is the last assignment action.
  • In loops, assignment step row order impacts flow correctness.
  • Use this trick to simplify and optimize collection building in flows.
  • Perform DML on the collection after the loop completes.

One reader of yesterdays email mentioned theres a flow function called INITCAP(text) which formats words in Sentence Case. A second reader mentioned you may need to handle exceptions like MacPerson, McDonald, or ONeal. Thanks to both of you for this feedback. Another interesting trick in flow can be found in the assignment step. Imagine you want to create a collection record variable from several single record variables. Normally this would be performed in a loop. The 1st assignment step in the loop is to assign the fields of the single record variable, say 22Account22. For example, Account.Name and Account.Type are set in the 1st step. The 2nd assignment step is to add Account to Accounts, which is a collection record variable. And then the loop repeats. Once the loop completes, you perform the DML operation on Accounts.

Flow BuilderSalesforce