I'm testing out an app that uses a callout to check some info in a government database and writes back any hits to a custom object.
The app is designed to be used via an action on a record page, but I need to fire it automatically via flow. They handed me a code sample to call via a trigger, which i wrapped in an invocable. This works fine on a single record, but fails on a bulk insert.
I've updated my invocable to run down different paths for single vs bulk inserts.
For the bulk path, I am trying to decide on whether to try batch apex with a custom iterator and a batch size of 1, which seems like it should work if I can wrap my head around iterators, or if its possible to do with queueables. At DF there were some statements to the effect that they are trying to make queueables better than batch apex, so seemed like there may be something here.
Copying the code below, but the question is more general. Is there any reason to use Batch Apex (since I need a batch size of 1), or can I use queuables.
Invocable Class (updated to separate callouts from DML)
public class Invocable_OFAC_Checker {
@invocableMethod(label='do the ofac check')
public static void doTheNeedful(list<Request> requestList){
list<ofacchecker.WSOFACScreeningService.OFACRequestWrapper> reqWrapperList = new list<ofacchecker.WSOFACScreeningService.OFACRequestWrapper>();
system.debug('in the invocable - req size ' + requestList.size());
FOR (request req : requestList){
string sFirstName = req.InputFirstName;
string sLastName = req.InputLastName;
string sEntityName = req.InputEntityName;
string sType = req.inputType;
string sName = req.inputName;
string sId = req.inputParentId;
ofacchecker.WSOFACScreeningService.OFACRequestWrapper oReqWrapper = new ofacchecker.WSOFACScreeningService.OFACRequestWrapper();
ofacchecker.WSOFACScreeningService.OFACResponseWrapper oResponseWrapper = new ofacchecker.WSOFACScreeningService.OFACResponseWrapper();
oReqWrapper.sFirstName = sFirstName; //Required for Individual Type
oReqWrapper.sLastName = sLastName; //Required for Individual Type
oReqWrapper.sEntityName = sEntityName; //Required for Entity Type
oReqWrapper.sType = sType; // sType can be 'Individual' or 'Entity' depending on requirement
oReqWrapper.sName = sName; //In case of Individual it would be the First Name and Last Name and for Entity it would be the Business Name
oReqWrapper.sParentRecordId = sId; // Record Id of the Parent object
reqWrapperList.add(oReqWrapper);
}
IF(reqWrapperList.size()>=1){
system.debug('in the req IF ' + reqWrapperList.size());
list<ofacchecker.WSOFACScreeningService.OFACResponseWrapper> respWrapperList = new list<ofacchecker.WSOFACScreeningService.OFACResponseWrapper>();
FOR(ofacchecker.WSOFACScreeningService.OFACRequestWrapper reqWrapper : reqWrapperList){
system.debug('in the callout FOR loop ');
ofacchecker.WSOFACScreeningService.OFACResponseWrapper oResponseWrapper = new ofacchecker.WSOFACScreeningService.OFACResponseWrapper();
oResponseWrapper = ofacchecker.WSOFACScreeningService.callOFACService(reqWrapper);
respWrapperList.add(oResponseWrapper);
}
FOR(ofacchecker.WSOFACScreeningService.OFACResponseWrapper respWrapper : respWrapperList){
system.debug('in the DML FOR loop ');
ofacchecker.Utility.storeOFACData(respWrapper.oOFAC, respWrapper.listOFACResults);
ofacchecker.Utility.populateOFACMatchResults(new Set<Id>{respWrapper.oOFAC.Id});
}
}
}
public class Request {
@InvocableVariable(label='First Name' description='Required for Individual Type')
public String inputFirstName;
@InvocableVariable(label='Last Name' description='Required for Individual Type')
public String inputLastName;
@InvocableVariable(label='Entity Name' description='Required for Entity Type')
public String inputEntityName;
@InvocableVariable(label='Type' required=true description='Set to \'Individual\' or \'Entity\' depending on requirement')
public String inputType;
@InvocableVariable(label='Name' description='In case of Individual it would be the First Name and Last Name and for Entity it would be the Business Name')
public String inputName;
@InvocableVariable(label='Parent Record Id' description='Flow on ofac object used to set custom relationship fields')
public String inputParentId;
}
}