I'm trying to use invocable apex within a record triggered flow to create a static flag to ensure that code only runs once for each transaction.
When I update more than one record I'm getting error:
FLOW_ELEMENT_ERROR The number of results does not match the number of interviews that were executed in a single bulk execution request.
I've tried adding the results with the invocable method to a static List, to ensure that the number of returned elements is equal to the number of invocations, but I'm still getting the same error.
public class FlowInvocable {
private static boolean run = true;
private static List<boolean> boolList = new List<boolean>();
@InvocableMethod
public static List<boolean> runOnce() {
if(run){
run=false;
boolList.add(true);
return boolList;
}else{
boolList.add(false);
return boolList;
}
}
}
The flow:
Record Triggered Flow Trigger - a record is created or updated, run flow after record is updated
then the only connected element is the invocable action above.
run
for controlling the execution/ similar to existing code). I suspect visual flow framework may be expecting 'List of List' in case bulk processing, but not sure without knowing more abt the req.