How To

Blink & You May Have Missed This Hidden Gem: Get Count Via Flow Assignment

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.


View image full screen

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.





15 thoughts on “Blink & You May Have Missed This Hidden Gem: Get Count Via Flow Assignment

  1. I was totally trying to do this with loops… and apparently so were other people. Thanks for this little walk through!


  2. 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!


  3. 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!


  4. 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 ?


  5. Great resource with easy steps for better understanding.please include looping concepts for next part of the flow


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s