0

I have an invocable Apex class that returns me a list of ids. But when I create an apex action at the level of my flow builder, I cannot store the list in a collection variable, it just offers me a simple variable. and my need is to retrieve this list of id and apply a loop on this list in my flow.

2

The InvocableMethod annotation is designed to handle Flows in bulk (e.g. Process Builder automations). To return a simple variable, you need to return a list, to assign to a collection, you must return a list of lists (e.g. List<List<Id>>). The size of the returned list must match the size of the input parameter list.

1

You should keep in mind that when writing invokable action, you actually write code which is running on multiple batched flows. So the logic inside the should loop List requests (inputs) and apply the logic to each input. Each input comes from one flow, If many flows are started at the same time. And that in a single flow when building it you have access to only one Results record. In order to have a list of objects returned you have to use somewhat of a wrapper object result and to have list variable in that result (wrapper) object. In your case:

from the Invokable method you return List<Result> and this is how the Result is declared.

global class Result {
                @InvocableVariable
                global List<ID> ids;
            }

I also suggest watching a few videos:

https://www.youtube.com/watch?v=FSqy1LWU9_o

https://www.youtube.com/watch?v=hXcES3tkw9Y

https://www.youtube.com/watch?v=V47MarDONY0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.