Skip to content

Instantly share code, notes, and snippets.

@justin-lyon
Created April 21, 2020 15:50
Show Gist options
  • Save justin-lyon/6cf483d7c9c34f0c76fa89005f11e907 to your computer and use it in GitHub Desktop.
Save justin-lyon/6cf483d7c9c34f0c76fa89005f11e907 to your computer and use it in GitHub Desktop.
public class CSVQueueable implements Queueable, Database.AllowsCallouts {
// Read in the CSV to a List<CSVRow>
// Persist the execution state across Async Queuable and Batch
private CSVState state;
// Count of Unique Policy Numbers to aggregate from the CSV
private Integer csvChunkSize;
public CSVQueueable (CSVState state) {
this(state, 1000);
}
public CSVQueueable (CSVState state, Integer chunkSize) {
this.state = state;
this.csvChunkSize = chunkSize;
}
public void execute (BatchableContext ctx) {
state.next(); // read the next 1000 unique policy numbers from the csv
state.getInProcessing() // => Set<String> policyNumbers
// Batch QueryLocator to process FROM Policy WHERE PolicyNumber IN state.getInProgress()
Database.executeBatch(new CSVBatch(state));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment