Last active
November 16, 2022 19:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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