How to pass record IDs from list view to a Flow in Lightning
Hi! 🙂
In this article, we are going to see how we can pass the IDs of multiple records from a list view to a Flow in Lightning. At present, there is no direct way to pass record IDs to a flow from the list view.
[Update January 2020]
I came across a much simpler solution for this which I would recommend using: https://forcepanda.wordpress.com/2021/03/09/how-to-mass-update-or-delete-records-from-list-views-in-lightning/ You can forget about the rest of the post! So the idea is to create a Visualforce page, which will pass the selected record IDs to a flow. The flow can either be a screen flow or a autolaunched flow. For our use case, we shall consider the flow type to be a Screen flow.
So without any further ado, let’s take a look at the steps.
Step 1: The first step is to create a flow to show all the selected record IDs. So, first we create a collection variable of string type, say AccountIDs, and then add a screen element to display the value of collection variable.


Save and activate the flow.
Step 2: Next, we will create an Apex class which will be the controller for our Visualforce page. PassSelectedIdsToFlowVFController.apxc
public class PassSelectedIdsToFlowVFController { public string[] SelectedAccountIDs{get;set;} public PassSelectedIdsToFlowVFController(ApexPages.StandardSetController listcontroller){ SelectedAccountIDs = new string[]{}; for(Account acc : (Account[])listcontroller.getSelected()){ SelectedAccountIDs.add(acc.Id); } }}
Step 3: Now we create our Vf page as follows: PassSelectedIdsToFlowVF.vfp
<apex:page standardController="Account" recordSetVar="Acc" extensions="PassSelectedIdsToFlowVFController" lightningStylesheets="true"> <flow:interview name="Mass_Action_List_View_Flow"> <!-- AccountIDs is flow input variable & SelectedAccountIDs is a property in the Apex controller --> <apex:param name="AccountIDs" value="{!SelectedAccountIDs}" /> </flow:interview> </apex:page>
Step 4: Next step is to create a list type button to call the Visualforce page and add it to the list view. To add the button to the list view, go to Search layouts -> List View.

Action time!

P.S. If you are looking to pass the IDs to an autolaunched flow, then you can simply call the flow from the apex itself. For reference: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/flow_interview_class.htm
Thank you! 😀

.png)




Comments