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.
https://releasenotes.docs.salesforce.com/en-us/summer18/release-notes/rn_forcecom_flow_operators.htm
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.
Quick Steps:
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.
This seems like an excellent way to do roll-up summaries!
LikeLiked by 1 person
I was totally trying to do this with loops… and apparently so were other people. Thanks for this little walk through!
LikeLike
thank you!
LikeLike
You’re welcome
LikeLike
You’re most welcome. Glad to give you this new little flow tip.
LikeLike
Jen you rock! I need this one. 🙂
LikeLike
Thanks, Matt
LikeLike
Hey Jen, this seems perfect for a number of rollup summary use cases! Do you have a recommended blog post that shows how I can build the rest of the flow that populates a rollup field on the Account or other object? And what’s the best way to distribute this flow? An autolaunched flow that runs when an Account is edited? Thank you!
LikeLike
This really depends on your use case in terms of where you need a rollup and what triggers it.
LikeLike
Hi Jen – I’ve been using this successfully but now have situations where my collection could be empty and I’m using the count result in a decision element. Have you heard of/had an issue where if your collection is NULL – no items, the Assign Count will return a value of 1? If so – any ideas for a workaround? Thanks!
LikeLike
I’ve not heard of this. I suggest you open up a Salesforce support case to report this.
LikeLike
Hi ,
I want to count the value based on decision .
let say we have total 6 total records of child for parent and after assigning the loop making decision special criteria and only 3 records are matching and need to store the count and update on parent .
do you have nay idea ?
LikeLike
If a record satisfies the decision criteria, you put it into another collection and count the value.
LikeLike
Great resource with easy steps for better understanding.please include looping concepts for next part of the flow
LikeLike
I do have a couple of blog posts on loop basics. Check those out and let me know if I missed a concept.
LikeLike