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.

Final Flow

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! 😀

24 thoughts on “How to pass record IDs from list view to a Flow in Lightning

  1. 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?

    Like

    • 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! 🙂

      Like

      • 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

        Like

      • 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. 🙂

        Like

  2. 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?

    Like

  3. Pingback: The Three Musketeers Arrive in Winter ’23: Data Table (Beta), IN Operator, and Record Type Filtering for Picklists – UnofficialSF

  4. After fetching the values in controller Construtor – SelectedAccountIDs.. How to pass them the SelectedAccountIDs to LWC?

    Like

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.