This tutorial explains how to pass selected record IDs from a Salesforce list view button to a Flow, enabling batch processing without writing Apex code.
Step 1: Create a Custom List Button
- Navigate to Setup > Object Manager > Your Object > Buttons, Links, and Actions.
- Create a new List Button with behavior "Execute JavaScript" and content source "OnClick JavaScript".
- Use the
{!Selected}merge variable to capture IDs (e.g.,var ids = '{!Selected}';).
Step 2: Build a Flow with an Apex Action
- Create an Autolaunched Flow that takes a text input for IDs.
- Add an Apex Action that parses the comma-separated IDs and performs your logic (e.g., update records).
- Save and activate the flow.
Step 3: Wire the Button to the Flow
- In your button JavaScript, call an Apex REST endpoint that invokes the flow, passing the IDs.
- Example JavaScript:
var ids = '{!Selected}';
if (ids == '') {
alert('Select at least one record.');
} else {
sforce.apex.execute('YourApexClass', 'invokeFlow', {recordIds: ids});
}
Full Example Code
Create an Apex class with a method to invoke the flow:
public class FlowInvoker {
@AuraEnabled
public static void invokeFlow(String recordIds) {
Flow.Interview.Your_Flow_Name flow = new Flow.Interview.Your_Flow_Name(new Map<String, Object>{'inputIds' => recordIds});
flow.start();
}
}
Note: Ensure your flow input variable name matches the parameter name used in the Apex call.
By following these steps, you can easily pass selected record IDs from a list view button to a Flow without coding complex triggers.