How to use Collection Filter in Salesforce Flow

In Salesforce flow, a collection filter is an element that filters out the records according to the filter conditions from its source, like a get record element. In this Salesforce tutorial, we will learn about the Collection Filter in Salesforce Flow and how and when to use it.

Collection Filter in the Salesforce Flow

In Salesforce, a collection filter is an element designed to process collections of records. This collection refers to a list-like structure that can hold multiple items, often records. The primary function of the collection filter is to evaluate these collections and return a subset of records based on specified criteria.

The use of a collection filter in Salesforce Flow enhances the efficiency and capability of flows, allowing users to process and filter large collections of records based on specific criteria without using multiple loops and collection variables in a flow.

Use Collection filter in Salesforce Flow

While working as a Salesforce system admin, I was assigned the task of segregating the Accounts into two lists using Flow. List1 will have accounts with annual revenue of more than 200k, and List2 will have accounts with annual revenue of less than 200k.

This flow could be created using screen flow with three get record elements: one for List1, second for List2, and third for all accounts. Then, we had to add loops and collection variables to make a list, but this approach would have made this flow complex for no reason.

See also  Auto-Update Custom Date field using Flow in Salesforce

In the below steps, I will explain how we can get the same output from the flow using the Collection Filter in Salesforce flow. Now, navigate to the Setup page of Salesforce and follow the below steps.

1. On the Setup page, go to the Quick Find box and search, then select Flows under Process Automation.

2. Click on the button New Flow, then in the next window, select the option Screen Flow and click Create.

3. Add a Get Record element to the flow and enter the Label for the Get Record element. Select the Condition requirement as None to get all Account records.

Under the heading How many records to store, select the option All records.

Use Collection filter in Salesforce flow

4. Add a Collection Filter element that will filter the accounts with Annual revenue of more than 200k.

Enter the Label for the collection filter, and in the Collection field, select the Get record element (Get Accounts).

According to the scenario above, I have selected Field as AnnualRevenue, Operator as Greater Than, and Value as 2000.

Salesforce Flow collection filter

5. Now, In the same way, we have added another Collection Filter element to filter out the accounts with annual revenue less than 200k.

Enter the label for the collection filter element, then again select the Collection as the Get Accounts element.

In the Condition requirements, I have selected Field as AnnualRevenue, Operator as Less than or Equal, and Value as 2000.

Add a Collection filter to the Salesforce flow

6. To display the filtered account, we will add a Screen element to the flow. Configure the screen flow according to the steps below.

  • To show the records from the two collection filters, We have added two Section elements on the screen, and then in that section, we will add data table elements to display records.
  • Enter the Label and the API Name for the data table.
  • In the Collection field, select the Collection filter element.
How to use Collection filter in a Salesforce Screen flow
  • To Configure the columns, we have selected the Account Name in Column to display account names in the Data table.
Sort records using Collection filter in Salesforce flow

In the same way, we have added another data table in the next section for the second Collection filter.

See also  How to Clone a Record with Flow in Salesforce

7. After configuring the Screen element, enter the Label and API Name for the screen element and click Done.

Use Collection filter in Salesforce Screen flow

8. After setting up the Collection Filter in the flow, save the flow with the relevant Label, and the Flow API Label will be auto-filled; after this, click Save.

The Screen flow is completed, now we will test and debug the flow in further steps.

Test and debug the flow

We will now debug the screen flow to check whether the collection filter is sorting the records.

1. Click on the Debug button in the flow builder.

Add a Collection filter element in a Salesforce Flow

2. In the debug window, click on the Run button.

How to Use Collection filter element in Salesforce Screen flow

3. After running the Screen flow, we can see that Accounts are sorted in the table list according to the filter conditions of the Collection filter element. Here, click Finish to end the flow.

Filter records in Salesforce flow with Collection filter

4. In the flow builder, click on the Activate button to activate the flow so that it can be used in the developer console.

Add a Collection filter element in a Salesforce screen flow

In this way, we can use or add the Collection filter element in the Salesforce Screen flow by following the above steps.

How to Call a Flow From Button in Salesforce | How to Launch Flow From Button in Salesforce

Conclusion

In Salesforce flows, using the Collection filter element saves time in the automation process and simplifies the flow structure by avoiding repetitive use of Loops and creating Collection variables.

In the above steps, we have understood the process of adding and configuring the Collection filter in a Salesforce screen flow; by now, you will be able to sort and filter the records in your flows using the Collection filter and enhance automation in your org.

See also  How to Automate Assets Creation using Flows in Salesforce

You may like to read: