I missed this Summer ’18 gem when reading through the Release Notes. I had quickly scanned the feature of setting Stages in flow. It wasn’t until MVP Stephanie Foerst mentioned this in Slack that I learned of this feature that slid under the radar.
You can now count the number of collection items and store that number in a variable. No more needing to loop through the collection to get the record count? WHAT?!
Business Case: Addison Dogster is the system administrator at Universal Containers. Mary Markle is the Director of Operations. As part of a process Mary has asked Addison to automate, Addison needs to count the number of records in a collection.
Solution: Addison uses flow for her process automation. Within that process, she performs a fast lookup to find all the cases associated with an account. Then she needs to determine how many cases are in the collection. Prior to Summer ’18, Addison would have to loop through the cases in the collection and increment the counter variable by 1. After the Summer ’18 release, Addison can now just use the Assignment flow element and using a number variable, use the new operation “Equals Count” to the sObject Collection Variable.
Note: This blog post will only focus on how to set up the Assignment element to obtain the collection itemm count.
1. Within Flow (Go to Setup | Create | Workflows & Approvals | Flows in Salesforce Classic or Process Automation | Flows in Lightning Experience), create the Record Count number variable to hold the collection item count.
2. Create an Assignment Flow Element to assign the count from the collection to the varRecordCount variable. Note: If your record count variable is not a number variable, the “equals count” will not show as an operator in your assignment element.
That’s it! No more loop de loops for the record count needed.