I have a Schedulable class that does multiple rollups from my Opportunities to their respective Accounts. This seems to work fine until recently I noticed some issues.
Essentially my Schedulable class is laid out like this:
Updated Added Complete Class
global class ScheduledOpportunityToAccountRollup implements Schedulable {
/* Unique list of accounts to be rolled up */
Set<String> account_list = new Set<String>();
/* Unique list of unpaid invoice opportunities to be rolled up */
Set<AggregateResult> unpaid_invoices = new Set<AggregateResult>();
global void execute(SchedulableContext sc) {
scheduleAccountsRevenueRollup();
scheduleAveragePastDueInvoiceRollup();
}
private void scheduleAccountsRevenueRollup(){
getAccountRevenueList();
if(!account_list.isEmpty()) OpportunityUtils.rollupAccountRevenues(account_list);
}
private void scheduleAveragePastDueInvoiceRollup(){
getAccountUnpaidInvoiceSet();
if(!unpaid_invoices.isEmpty()) OpportunityUtils.rollupAverageDaysPastDue(unpaid_invoices);
}
/**
* GET ACCOUNT REVENUE LIST
* Opportunities must have Labor Services and either be paid or past due in order to be included in this scheduled batch
*/
private void getAccountRevenueList(){
List<Account> accounts = new List<Account>([SELECT Id FROM Account WHERE Total_Balance2__c != 0 OR Current_or_Previous_Customer__c != null]);
for(Account a : accounts){
account_list.add(a.Id);
}
}
/**
* GET ACCOUNT UNPAID INVOICE SET
* Opportunities must have Labor Services past due in order to be included in this scheduled batch
*/
private void getAccountUnpaidInvoiceSet(){
unpaid_invoices = new Set<AggregateResult>([
SELECT AccountId, COUNT(Id) Invoices, AVG(Days_Past_Due__c) Average, MAX(Days_Past_Due__c) Max
FROM Opportunity
WHERE IsDeleted = FALSE
AND Invoice_Num__c != ''
AND Is_Paid__c = FALSE
GROUP BY AccountId
]);
}
}
When this runs I have issue with some accounts not being rolled up in the 2nd method scheduleAveragePastDueInvoiceRollup()
. So when troubleshooting I removed the first one scheduleAccountsRevenueRollup()
and this time everything in scheduleAveragePastDueInvoiceRollup()
worked exactly as expected.
SO, question is, am I not allowed to run multiple methods that each have their own transactions? At the moment I'm not seeing script errors from any governing limits, just finding issues on accounts that aren't being rolled up.
Database.setSavePoint()
etc... – Daniel Ballinger May 26 '15 at 22:27UPDATE Accounts
– Xtremefaith May 27 '15 at 0:40