Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. /* A simple batch Apex class to demonstrate updating a field on Opportunity
  2. * Can be executed from Anonymous Apex using 2 lines:
  3. * OpportunityBatch oppBatch = new OpportunityBatch();
  4. * database.executeBatch(oppBatch);
  5. */
  6. global class OpportunityBatch implements Database.Batchable<sObject> {
  7. global Database.QueryLocator start(Database.BatchableContext BC) {
  8. String query = 'SELECT Id,Name FROM Opportunity';
  9. return Database.getQueryLocator(query);
  10. }
  11.  
  12. global void execute(Database.BatchableContext BC, List<Opportunity> scope) {
  13. for(Opportunity opp : scope)
  14. {
  15. opp.Name = opp.Name + '-Updated';
  16. }
  17. update scope;
  18. }
  19.  
  20. global void finish(Database.BatchableContext BC) {
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement