Hello folks,
How powerful are the collection sort and collection filter elements? How should you use them?
I experimented with collection filter and collection sort elements to see how far I can go using only one get element. In other words, I wanted my flow only to use up one SOQL against the governor limits.
I started with a get element that returns all the cases that have both account and contact assignments. I was able to extract the following information with only one get element:
- Most Recently Modified Case
- Oldest Modified Case
- Oldest Modified Case Account Name
- Number of Cases by this Account
- Most Recently Closed Date for this Account
- Contact Id on this Case
- Number of Cases for this Contact
- Oldest Closed Date for this Contact on this Case
Please see the image for the results.
How many elements did I use? Did I have to loop?
Here are the answers:
- Your get element gives you sorting functionality. Use it.
- You have to loop to get the min and max values, such as the oldest and most recent, sorted by Date and Time. But you need to loop only for one iteration. So you can exit after you assign the first record to a variable.
- Your loop can use the existing sort or the reverse sort. Use this functionality.
- Initially, I used a counter variable to exit the loop, but this was unnecessary. You need to exit the loop regardless after the first iteration. Insert a decision and connect both branches to the next element outside the loop.
- You can get a count of records by using an assignment element with the operator “equals count”.
I experimented with the formula criteria inside the collection filter element without much luck. I think this functionality does not allow for filters with variable values on the right side of the equation. “ContactId on the current record = ContactIdVariable” formula did not work.
What do you think? Can these elements save you lengthy loops and executed elements?
How many elements, excluding the start or the end element, did I use to extract this information.
Join the discussion on LinkedIn here or Twitter here.
Live session recording links:
Watch Melody Lwo of Salesforce Flowsome and me either on LinkedIn here or YouTube here.
Enjoy.
P.S. Originally published on 05/30/2022.
Read the previous issue of the newsletter here.
Read the next issue of the newsletter here.
Subscribe to the weekly educational Salesforce Flow Tips newsletter here.
Pingback: The Answer for the Collection Filter & Collection Sort Challenge – Salesforce Flow Tips Newsletter | Salesforce Break