Skip to content

Instantly share code, notes, and snippets.

@TheShubhamVsnv
Created March 17, 2024 15:26
Show Gist options
  • Save TheShubhamVsnv/f04c68c23e161dc156062c7c61232352 to your computer and use it in GitHub Desktop.
Save TheShubhamVsnv/f04c68c23e161dc156062c7c61232352 to your computer and use it in GitHub Desktop.
global class UpdateAccountNames implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
// Collect batches of Account records to be processed
String query = 'SELECT Id, Name FROM Account';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Account> accList) {
// Process each batch of records
for(Account acc : accList) {
// Update the Account Name
acc.Name = acc.Name + ' - Updated';
}
// Update the Account records
update accList;
}
global void finish(Database.BatchableContext BC) {
// Perform post-processing operations if needed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment