Created
June 15, 2019 16:29
-
-
Save AlwaysThinkin/34ee300b5c36436581cae756adf96376 to your computer and use it in GitHub Desktop.
This file contains 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
/* 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