Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class BatchAccountRevenue implements Database.Batchable<sObject>,Schedulable
- global Database.QueryLocator start(Database.BatchableContext BC)
- {
- String query = 'Select Id, Name,All_Time_Revenue_c from Account';
- return Database.getQueryLocator(query);
- }
- global void execute(Database.BatchableContext BC, List<Account> scope)
- {
- for(Account a : scope)
- {
- AggregateResult[] agList = [SELECT SUM(Normalized_Amount__c) totalSum FROM Invoice__c where Normalized_Amount__c!= null and Id=:a.id];
- a.All_Time_Revenue_c = (double)agList[0].get('totalSum');
- }
- update scope;
- }
- global void finish(Database.BatchableContext BC){
- }
- global void execute(SchedulableContext sc) {
- BatchAccountRevenue batchable = new BatchAccountRevenue();
- Database.executeBatch(batchable, 300);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement