I am attempting to create a class that takes a collection of records from a flow and processes any pending approval requests in that collection of records. In my code below I'm getting an error on line 26 where I'm trying to create the list of pending approval requests:
Invalid bind expression type of List for column of type Id
I am using the IN operator as someone suggested prior but I'm still seeing that same error. I would need to keep List<List<String>>
as I can't pass a collection variable to a normal list, it has to be a list of list. Any help is appreciated!
Thank you!
global class ProcessApproval implements queueable {
InvocableVariables[] request;
public ProcessApproval(InvocableVariables[] request) {
this.request = request;
}
@InvocableMethod
public static void ProcessApprovalMethod(List <InvocableVariables> request){
System.enqueueJob(new ProcessApproval(request));
}
public void execute(QueueableContext context) {
//invocable variables
Id recordToProcess = request[0].recordToProcess;
String actionToPerform = request[0].actionToPerform;
List<List<String>> recordIDs = request[0].recordIDs;
//try/catch block for error handling
try {
List<ProcessInstanceWorkitem> workItems = [
SELECT Id, ProcessInstanceId
FROM ProcessInstanceWorkitem
WHERE ProcessInstance.TargetObjectId IN :recordIDs
];
List<Approval.ProcessWorkitemRequest> requests = new List<Approval.ProcessWorkitemRequest>();
for(ProcessInstanceWorkitem workItem : workItems){
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setWorkitemId(workItem.Id);
req.setAction(actionToPerform);
req.setComments('Processed via backend automation.');
requests.add(req);
}
Approval.ProcessResult[] processResults = Approval.process(requests);
}
catch(Exception ex) {
system.debug('Exception has occured' + ex.getMessage());
}
}
global class InvocableVariables{
//Source record ID
@InvocableVariable public Id recordToProcess;
//Approve/Reject/Recall action
@InvocableVariable public String actionToPerform;
//List of record IDs to process
@InvocableVariable public List<List<String>> recordIDs;
}
}