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).
Even if you add a decision to check the record count, it is still not recommended to perform Get Records element inside a loop. Instead, you can use custom solutions which can be installed from unofficialsf.com.
Install this custom action, which converts a text collection that contains Ids to a record collection. Pass parameters to the action and it will generate a record collection. By doing so, you can remove the loop and the Get Records action inside it.