Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class CountAssets implements Database.Batchable<sObject> {
- global Database.QueryLocator start(Database.BatchableContext context) {
- return Database.getQueryLocator([Select AccountId,Name, Quantity,Status s,UsageEndDate from Asset where Status='Purchased' or Status='Expired' ]);
- }
- global void execute(Database.BatchableContext context, List<Account> scope) {
- Account[] updates = new Account[] {};
- for (Asset a:AccountId)
- {
- if(Status=='Expired')
- updates.add(new Account(Id =(Id) ar.get('a'),Number_of_inactiveAssets__c = (Decimal) ar.get('c')));
- else
- updates.add(new Account(Id =(Id) ar.get('a'),Number_of_activeAssets__c = (Decimal) ar.get('c')));
- }
- update updates;
- }
- public void finish(Database.BatchableContext context) {
- }
- }
- global void execute(Database.BatchableContext context, List<Asset> scope) {
- for(Asset a : scope)
- {
- if(a.status == 'Expired)
- //your logic
- else
- //your logic
- }
- update scope;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement