20 lines
792 B
OpenEdge ABL
20 lines
792 B
OpenEdge ABL
global class UpdateAccountCloseDealAmount implements Database.Batchable<sObject> {
|
|
global Database.QueryLocator start(Database.BatchableContext BC) {
|
|
return Database.getQueryLocator('SELECT Id, CloseDealAmount__c, (SELECT Amount FROM Opportunities WHERE StageName = \'Closed Won\') FROM Account');
|
|
}
|
|
|
|
global void execute(Database.BatchableContext BC, List<Account> scope) {
|
|
for(Account acc : scope) {
|
|
Decimal maxAmount = 0;
|
|
for(Opportunity opp : acc.Opportunities) {
|
|
if(opp.Amount > maxAmount) {
|
|
maxAmount = opp.Amount;
|
|
}
|
|
}
|
|
acc.CloseDealAmount__c = maxAmount;
|
|
}
|
|
update scope;
|
|
}
|
|
|
|
global void finish(Database.BatchableContext BC) {}
|
|
} |