Passing multiple collection variables from flow into an apex method using Invocable Variables

apexvariablevisual-workflow

I'm trying to pass four collection variables to be processed in apex but having a difficult time implementing invocable variables to allow for more than the single parameter an invocable method can take.

I suspect it has to do with the List<List> syntax, but I can't seem to get it right. Can someone point me in the right direction? Is this even possible? Should I just call separate apex actions instead? That seems inefficient.

With the below output, I cannot get the variables to appear for input in flow. When I change them back to normal lists, they show up correctly, but only present null values to the invocable method executing on them.

public without sharing class fileUploadController {


   public class flowInputs {
        @InvocableVariable
        public List<List<String>> psrTestList;

        @InvocableVariable
        public List<List<String>> poaTestList;
    }

    @InvocableMethod
    public static void psr(List<List<flowInputs>> request) {
        List<String> results = new List<String>();

        for (List<flowInputs> r : request) {
            system.debug('test '+ r);
            
        }
    }

Best Answer

To pass in a collection, use List<Type> (for the appropriate Type), and use List<Wrapper> for the input parameter (which translates to just a Wrapper for each Flow Input).

So, the correct code should be:

public class flowInputs {
    @InvocableVariable
    public List<String> psrTestList;

    @InvocableVariable
    public List<String> poaTestList;
}

@InvocableMethod
public static void psr(List<flowInputs> request) {

You're likely getting confused because you'd see this in an example:

@InvocableMethod public static void psr(List<List<String>> request) {

In order to allow a Collection of type String to be brought in. This is because the parameter itself is bulkified, which means the top-level List actually represents a bulk input of data.

Related Topic