Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. global class CountAssets implements Database.Batchable<sObject> {
  2.  
  3. global Database.QueryLocator start(Database.BatchableContext context) {
  4. return Database.getQueryLocator([Select AccountId,Name, Quantity,Status s,UsageEndDate from Asset where Status='Purchased' or Status='Expired' ]);
  5. }
  6.  
  7.  
  8. global void execute(Database.BatchableContext context, List<Account> scope) {
  9. Account[] updates = new Account[] {};
  10. for (Asset a:AccountId)
  11. {
  12. if(Status=='Expired')
  13. updates.add(new Account(Id =(Id) ar.get('a'),Number_of_inactiveAssets__c = (Decimal) ar.get('c')));
  14. else
  15. updates.add(new Account(Id =(Id) ar.get('a'),Number_of_activeAssets__c = (Decimal) ar.get('c')));
  16. }
  17. update updates;
  18. }
  19.  
  20. public void finish(Database.BatchableContext context) {
  21. }
  22. }
  23.  
  24. global void execute(Database.BatchableContext context, List<Asset> scope) {
  25. for(Asset a : scope)
  26. {
  27. if(a.status == 'Expired)
  28. //your logic
  29. else
  30. //your logic
  31. }
  32. update scope;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement