I have have a list of formats of a file I need to download via API from a 3rd party service.

List<String> FileFormatList = new List<String>{a1s,
// FileFormatList.size() = 178

I want to do something like:

ThirdPartyConnection ApiCon = new ThirdPartyConnection('credentials');
Id ParentId;
for(String FileFormat :FileFormatList){
        String FileCsvString = ApiCon.getFile(FileFormat);
        Attachment FileAttachment = new Attachment(Name=FileFormat+'.csv',
        insert FileAttachment;
    } catch(Exception Whoops){
        System.debug('ERROR @ '+FileFormat+'; Exception: '+Whoops);

The issue is that each instance of the for loop really needs its own Execution Context. Can this be done with Batch code / implementing Database.batachable?

PS: I am writing this Q&A-style and will be posting an example


I think this post will get you there - it explains how you can invoke a batch with a scope of 1 with a iterator (in your case a List) - so using this approach, you can pass each string from the list into its own batch execution

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.