Skip to content

Instantly share code, notes, and snippets.

@jongpie
jongpie / MultiQueryExampleBatchJob.cls
Last active April 9, 2025 12:08
Example Apex batch job that runs multiple queries for different SObject Types
public without sharing class MultiQueryExampleBatchJob implements Database.Batchable<SObject>, Database.Stateful {
private Schema.SObjectType currentSObjectType;
// Add any SObject Types here if you want the batch job to query them
private List<Schema.SObjectType> sobjectTypes = new List<Schema.SObjectType>{ Schema.Account.SObjectType, Schema.Contact.SObjectType };
public Database.QueryLocator start(Database.BatchableContext context) {
this.currentSObjectType = this.sobjectTypes.remove(0);
return this.getQueryLocator();
}