Skip to content

Instantly share code, notes, and snippets.

@AlwaysThinkin
Created June 15, 2019 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlwaysThinkin/34ee300b5c36436581cae756adf96376 to your computer and use it in GitHub Desktop.
Save AlwaysThinkin/34ee300b5c36436581cae756adf96376 to your computer and use it in GitHub Desktop.
/* A simple batch Apex class to demonstrate updating a field on Opportunity
* Can be executed from Anonymous Apex using 2 lines:
* OpportunityBatch oppBatch = new OpportunityBatch();
* database.executeBatch(oppBatch);
*/
global class OpportunityBatch implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
String query = 'SELECT Id,Name FROM Opportunity';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
for(Opportunity opp : scope)
{
opp.Name = opp.Name + '-Updated';
}
update scope;
}
global void finish(Database.BatchableContext BC) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment