Ad Code

How to pass multiple parameters from flow to apex class

Pass multiple parameters from flow to apex

In this article, we'll explore how to effectively pass multiple parameters from a flow to an Apex class in Salesforce Lightning.

If you attempt to create an invocable method that accepts multiple input parameters, you may encounter the error Only one parameter is supported on methods with @Invocable annotation

To resolve this, you can define an inner class with multiple variables, each annotated with @InvocableVariable. Here are the steps to follow for this approach.

Step 1: Create an apex class (Name: OpportunityHandler)

public class OpportunityHandler {
    @InvocableMethod(label = 'Create Opportunity Line Items')
    public static void CreateOpportunityLineItems(
List<OppAndAccountDetailsRequest> requestList){
        system.debug('CreateOpportunityLineItems method');
        system.debug('requestList >> ' + requestList);
        List<Opportunity> oppoCollection = requestList[0].oppList;
        system.debug('oppoCollection >> ' + oppoCollection);
        List<Account> accountCollection = requestList[0].accList;
        system.debug('accountCollection >> ' + accountCollection);
        String accountName = requestList[0].accountName;
        system.debug('accountName >> ' + accountName);
    public class OppAndAccountDetailsRequest{
        public list<opportunity> oppList;
        public list<Account> accList;
        public string accountName;

Step 2: Create a flow and invoke the newly created apex class

The complete flow looks as below (Record-Triggered Flow on opportunity object)

Record-triggered flow in the salesforce

In the apex action, we pass three variables to the Apex class: the Opportunities list, the Account list, and the Account name

Apex action in the salesforce lightning flow

Newly created record-triggered flow executes on an update of any Opportunity record. 
To test it, you can update an Opportunity record and examine the debug logs in the developer console.

Developer console in the salesforce org

If you have any questions or comments, please leave them in the comments section below.

Until then…

Post a Comment