Visual Workflow allows us to automate business processes by building applications, known as Flows. Using Flows, a user can collect information; or, they can update, edit, or create records in Salesforce. Furthermore, Flows can execute logic, interact with the Salesforce database, call Apex classes, Platform Events, and guide users through various screens to streamline the process of collecting and updating data.
Once a Flow is built, an Admin can make the Flow available to the right users or systems.
If you have the basic understanding of Apex then, you can write a query to get records and count the list size. For example, using Apex, one can get all Contacts that belong to city Alpharetta and, count list size, by writing the following code:
List<Contact> myContact = new List<Contact>(); myContact = [Select id, Email from contact where Mailingcity ='Alpharetta']; system.debug('Size of List'+myContact.size());
Now suppose you wonder, can I achieve the aforementioned outcome by using Flow? Well, you are in luck! For, before Summer’18 release, it was very complex to count the SObject Collection variable (Kind of equivalent to Apex list).
But, since Spring’18 release, a user can use Assignment element to count the SObject Collection Variable size and store that number in a variable without using the Loop element!
Business Use Case
Edward Backhouse is working as System administrator at GurukulOnCloud. He received a requirement to count Contact records where Mailing city equals Alpharetta. The new feature of Flow to rescue!
The solution for the above business requirement
There are few possible solutions for the above business scenario. One of them, of course, is to continue to use the old method, as shown in the preceding screenshot.
But, Edward is a Salesforce Ninja like us! And, therefore, he is always on a lookout for feature enhancements. As a result, Edward knows that, after Summer’18, he can solve the above requirement efficiently! So, instead of resorting to the old method, he takes following the steps:
- Edward navigates to Setup (Gear Icon) | Setup | Process Automation | Flows in Lightning Experience.
- Then he clicks on the New Flow button – which, in turn, opens the Flow canvas.
- Edward creates a Variable (to store record count) as shown in the following screenshot: Read the rest of this entry!