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! 😀
This is great but I would like to use a flow screen element (new Lookup component) that only works if lightning run time is enabled which prohibits the use of visualforce as the source of the flow. Any thoughts on another solution?
LikeLike
Hi Gina,
I do have an idea. I will test it out and if it works might just blog it. May take a day or two. Will keep you posted. You can subscribe to the blog just in case you don’t want to miss the update.
Thanks! 🙂
LikeLike
Great – since I posted I did come up with something that seems to work which is that apparently we can use a (possibly new?) “hidden feature” of flow. If we create a collection variable (not an Sobject record collection variable) and name it “ids” – must be lower case, it will automagically pass the record ids in without the visualforce page. It doesn’t pass the entire record so you need to use a combination of Loop and Get Records (unfortunately inefficient) but it did work. You then launch the URL from a list view button, instead of using visualforce.
I still need to figure out how to generally launch flow from a visualforce button for another use case (no list view) but it seems like there may be a way to use lightning out to accomplish that. I’m still working on it! Thanks, Gina
LikeLike
Whoa!! This is quite a discovery. Would you like to post this as a blog article on my blog?
And for your use case, I would suggest creating another vf page(call your flow inside this page) and call it using a button on the existing vf page. That would be the ideal way to go about it. 🙂
P.S. If you do not have the time to blog about the interesting discovery you made, I would like to blog about it crediting it to you, with your permission ofcourse. 🙂
LikeLike
Actually I’m not the originator of this. Here’s the blog post I used to figure this out. https://xbaf.com/flow-list-buttons.
LikeLike
Man, this blog is dope!!!
Thanks Gina. 😀
LikeLike
How could we achieve this without a standard controller? Need to add the button on a custom object list view?
LikeLike
I recently found out about this, which is way more easy than my solution.
https://xbaf.com/flow-list-buttons
LikeLike
This link seems to be broken… any idea where the article may have gone? Or maybe you could give us a summary?
LikeLike
Here you go:
https://forcepanda.wordpress.com/2021/03/09/how-to-mass-update-or-delete-records-from-list-views-in-lightning/
LikeLike
Wait… I think I might have found it. Is this the one you refer to? https://www.xbaf.com/flow-list-buttons
LikeLike
This is nice!
For the controller, I’m not quite familiar with how to write a test class for it. I tried but I think I’m missing something in the code so I get an error when I save it.
Any suggestions?
LikeLike
Refer this post, where I have used a simple way to pass the IDs: https://forcepanda.wordpress.com/2020/01/28/how-to-mass-update-or-delete-child-records-from-related-lists-in-lightning-using-flows/
LikeLike
How to display modal in listview page
LikeLike
Hi Narender,
How to iterate list of lds in flow.
Thanks,
Anil Kumar
LikeLike
Hi,
Simply using a for loop. 🙂
LikeLike
istcontroller.getSelected() is returning null, even I Selected three records from listview.
LikeLike
You don’t need to use a VF page, you can directly pass ids to flow. Check the “January Update” section at the beginning of the post.
LikeLike
Pingback: The Three Musketeers Arrive in Winter ’23: Data Table (Beta), IN Operator, and Record Type Filtering for Picklists – UnofficialSF
Hi
Iam trying to create Two Records by clicking that List view button
LikeLike
What’s the issue you’re facing?
LikeLike
After fetching the values in controller Construtor – SelectedAccountIDs.. How to pass them the SelectedAccountIDs to LWC?
LikeLike
You can use a simpler approach.
https://forcepanda.wordpress.com/2021/03/09/how-to-mass-update-or-delete-records-from-list-views-in-lightning/
LikeLike
To lwc, you can’t. Better to call the lwc inside the flow itself.
LikeLike