With the Winter 21 release we have added the capability to select records in a related list and send the records to Flow! This is a big enhancement that we think many will find great uses for. There are a few pieces of setup. To help with understanding of how this works, we’re gong to create a button on the Contact related list from an Account Page to be able to send selected Contacts to a Flow.
First, you’ll need to work with the Related List Type of Enhanced List. This will allow you to select multiple records in the related list.
Next, you’ll need to create a VERY small Visualforce Page. You might be asking why. Well, in a very technical description, we’re using the functionality in the standard controller on an object to do our work. For those less technical, Salesforce has capabilities in a Visualforce Page that allows us to send the selected record to it. But don’t worry, the Visualforce Page is going to redirect to your Flow with the records you selected!
Below is the screen shot of the Visualforce Page. The syntax will always be the same, but you’ll be setting the StandardController part of the page to be what your object name is, whether it is Account, Contact, or Custom_Object__c, you need the API name of your object of the related list. I’ve highlighted the part that you need to update to use with your object. In the example below, we’re using the standard Contact object, so we’re going to be selecting multiple Contacts. Just replace it with your object API name.
Ensure that your users have access to the redirectToFlow Apex Class in profiles/permissions, as that is what does the magic.
Once you have your Visualforce Page, you need to create the button. There’s two parts to the button that you need to consider. First, what is the object your related list is part of. In our example, this is the Contact. Second, you’ll need to know what the object is that is displaying your related list, in this example, the Account. This is important as we send information to the Flow. There are two variables that need to be added to the Flow. First, is the recordId. In our example, that would be the Account, as that is the “launching” object that we are clicking the button from. In your Flow, you need a text variable named recordId (spelled exactly like that) that you’ll send the main record to that allows for input.
Second, you’ll need a variable named ids (spelled exactly like that) that is a text variable which allows for multiple values, available for input. Example below.
Now, for the button, the ids you’re sending into are the Contact records, and the main record that you’re sending in is the Account. So, you need a button on the Contact object like below. I’ll break down the button after.
The first part is that this is a formula button using the URLFOR formula. You’ll be using “/apex/” as the start and the API name of your Visualforce Page as the second part. Since our example uses a Visualforce Page named “Contacts_To_Flow”, we’ll have our first part of the URLFOR formula be “/apex/Contacts_To_Flow”. After that, you’re not using the “standard” Id, so write null. The next part is where you define your Flow and the “launching” object Id. So, we put this in brackets. First, “flowName” spelled just like that is what is needed to set the name of the Flow. Then, an equals sign, and the API name of your Flow. In this example, I’m using “flowName=”Show_Contacts””. Put a comma after that as you are defining a new parameter, and here you can set “recordId” as the record Id of the “launching” object. This is important. In the example, we’re using Account.Id. This is because the button is being launching from the Account, so you’re sending the Account Id to the flow as the record Id. It should be written like “recordId=Account.Id”. Notice that in the first part, flowName, you need to put quotation marks around the API name of the Flow, but those are not used in the object Id part.
Your button should be a List Button where Display Checkboxes (for Multi-Record Selection) is checked.
And that’s it for your button! The last part is inside your flow.
Since the Visualforce Page just sends in record Ids, and not the actual records, there is a new Action in Flow Components to be able to get the records from the Ids. First, you’ll need to create a new Variable, data type of Record, which allows multiple values, and set it to the object of the ids. In this example, Contact is the object. Below is an example of the variable.
After that, grab the Action from Interaction on the Flow Canvas and find the Get Records WHERE Id is IN List. You’ll send in the ids variable that was created earlier and manually assign variables, setting the Record Collection Variable with the variable you just created for the records. Example screen shot below.
And that’s it! Now the records that your user selects in the related list will be available in the Record Collection Variable for you to use within the Flow!
Want to get all the field values and a full collection of records? Check out the Query Records by List of Ids in Flow post to see how to do it!