Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Last active November 16, 2022 19:19
Show Gist options
  • Save matthewpoer/e6e8c988cc42660829c4b785f46d1bbb to your computer and use it in GitHub Desktop.
Save matthewpoer/e6e8c988cc42660829c4b785f46d1bbb to your computer and use it in GitHub Desktop.
Class to batch update records but make not changes. Useful to trigger a flow to take effect on existing data that writes a new field. Replace !!ObjectType!! with your object, e.g. Contact or Lead or CustomObject__c
global class EmptyUpdateBatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id FROM !!ObjectType!! WHERE Field = NULL';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<!!ObjectType!!> records) {
update records;
}
global void finish(Database.BatchableContext BC) {}
}
EmptyUpdateBatch batchy = new EmptyUpdateBatch();
Id batchId = Database.executeBatch(batchy);
System.debug(batchId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment