Passing Multiple Records to Flow

Passing Multiple Records to Flow

There are many ways to launch a flow. In most of these ways, it is clear how to pass parameters to the flow. If you use a Process Builder, you can pass any value to any input variable of the flow, if you use a Lightning Page, you can pass the record Id or a text to any input variable etc. It is clear because Salesforce guides you how to pass the parameters. However, when you launch a flow with an action button, it is not clear how to pass the Id of the current record, it does not guide you how to do it. You just have to know that there should be a input text variable with name “recordId” in your flow, then the action button automatically passes the current record’s Id to this variable.

All of these ways are related to launching a flow for a single record. What if you want to launch a flow for multiple records at once? If you had a way to select multiple records and launch a flow with one click, that would be great, right? Well, that’s possible!

Basically, you will need to create a custom button that will launch the flow and put it to the list views. After you select multiple records and click this button, your flow will run for the selected records.

How To Do?

1- First of all, you have to create a flow that can work with multiple records. Most likely, you will need to use loops. To learn how to use loops, read this post: Working with Collections in Flow

2- Create a text collection variable with name “ids” and make it available for input. Note that name of this variable is case sensitive.

3- Create a custom button with type List Button and mark the checkbox to display checkboxes for multi-record selection. Content source should be URL and for the URL value, simply put your flow’s URL.

You don’t have to pass anything to the flow. When it is configured correctly, Salesforce automatically populates the “ids” collection variable with the IDs of the selected records.

Just a quick note, if you create a custom button that will be displayed on the detail page, then you have to name your input text variable as “id” but not “ids”.

4- According to your use case, perform a loop to bring more values from the selected records. To avoid hitting the governor limits about SOQL queries, use assignment and decision elements to check the size of the collection. To learn how to check a collection’s size, read this post: Working with Collections in Flow

In the example below, a get element is used inside a loop. Even though it is not recommended, since it makes sure that there are maximum of 20 records in the collection, flow will not hit the SOQL queries limit (limit is 100).

1 Trackback / Pingback

  1. Using Flow to Mass Delete Records from List View - Salesforce Time

Leave a Reply

Your email address will not be published.


*