Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. global class BatchAccountRevenue implements Database.Batchable<sObject>,Schedulable
  2.  
  3. global Database.QueryLocator start(Database.BatchableContext BC)
  4. {
  5. String query = 'Select Id, Name,All_Time_Revenue_c from Account';
  6. return Database.getQueryLocator(query);
  7. }
  8.  
  9. global void execute(Database.BatchableContext BC, List<Account> scope)
  10. {
  11. for(Account a : scope)
  12. {
  13.  
  14. AggregateResult[] agList = [SELECT SUM(Normalized_Amount__c) totalSum FROM Invoice__c where Normalized_Amount__c!= null and Id=:a.id];
  15.  
  16. a.All_Time_Revenue_c = (double)agList[0].get('totalSum');
  17. }
  18. update scope;
  19. }
  20. global void finish(Database.BatchableContext BC){
  21. }
  22. global void execute(SchedulableContext sc) {
  23. BatchAccountRevenue batchable = new BatchAccountRevenue();
  24. Database.executeBatch(batchable, 300);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement