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.

ReleaseNotes.GIF

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?!

MindBlownATT.gif

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.

FlowCollectionWithCount.GIF

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.

varRecordCount.GIF

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.

FlowAssignment.GIF

That’s it! No more loop de loops for the record count needed.

 

 

 

 

20 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!

    Like

  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!

    Like

  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!

    Like

  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 ?

    Like

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

    Like

  6. Hi Jen,

    If I want to show the count of specific child records on the parent field wouldn’t I still need to use a loop with an update element outside of it at the end, in order to avoid hitting dml limits? I assumed your example was not for record triggered flows that update a parent field with the count figure.

    Like

  7. No, you don’t need a loop if a you are doing is getting a count of child records. You do a Get Records for the child records. Then an assignment to determine the count of the records from the Get Records. Lastly, a Update Records to update the parent field with the count of child records. That’s it. No need for looping.

    Like

  8. Hi Jen, is this still possible in the new cloud designer? I have a get records action and then am trying to build the assignment, but can’t find a recordcount option to assign to my variable.

    Like

  9. Yes, it still works in Flow Builder. You have to create a variable that is a number data type and that will unlock the “Equals Count” operator.

    Like

Comments are closed.