Skip to content

Commit

Permalink
Fix for issue 4
Browse files Browse the repository at this point in the history
  • Loading branch information
afawcettffdc committed Sep 1, 2013
1 parent 859a881 commit 3c2f9ae
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 1 deletion.
9 changes: 8 additions & 1 deletion rolluptool/src/classes/LREngine.cls
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,16 @@ public class LREngine {
for (String detailFld : detail2MasterFldMap.keySet()) {
Object aggregatedDetailVal = res.get(detail2AliasMap.get(detailFld));
masterObj.put(detail2MasterFldMap.get(detailFld), aggregatedDetailVal);
}
}
// Remove master Id record as its been processed
masterIds.remove(masterRecId);
}

// Zero rollups for unprocessed master records (those with no longer any child relationships)
for(Id masterRecId : masterIds)
for (String detailFld : detail2MasterFldMap.keySet())
masterRecordsMap.get(masterRecId).put(detail2MasterFldMap.get(detailFld), 0);

return masterRecordsMap.values();
}

Expand Down
95 changes: 95 additions & 0 deletions rolluptool/src/classes/RollupServiceTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,101 @@ private with sharing class RollupServiceTest
// Assert rollup
System.assertEquals(0, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue);
}

private testmethod static void testSingleRollupWithInsertThenDelete()
{
// Test supported?
if(!TestContext.isSupported())
return;

// Configure rollup
LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c();
rollupSummary.Name = 'Total Opportunities greater than 200 into Annual Revenue on Account';
rollupSummary.ParentObject__c = 'Account';
rollupSummary.ChildObject__c = 'Opportunity';
rollupSummary.RelationShipField__c = 'AccountId';
rollupSummary.RelationShipCriteria__c = null;
rollupSummary.FieldToAggregate__c = 'Amount';
rollupSummary.AggregateOperation__c = 'Sum';
rollupSummary.AggregateResultField__c = 'AnnualRevenue';
rollupSummary.Active__c = true;
rollupSummary.CalculationMode__c = 'Realtime';
insert new List<LookupRollupSummary__c> { rollupSummary };

// Test data
Account account = new Account();
account.Name = 'Test Account';
account.AnnualRevenue = 0;
insert account;
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Open';
opp.CloseDate = System.today();
opp.AccountId = account.Id;
opp.Amount = 100;
insert opp;

// Assert rollup
System.assertEquals(100, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue);

// Delete Opportunity
delete opp;

// Assert rollup
System.assertEquals(0, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue);
}

private testmethod static void testSingleRollupWithInsertsThenDelete()
{
// Test supported?
if(!TestContext.isSupported())
return;

// Configure rollup
LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c();
rollupSummary.Name = 'Total Opportunities greater than 200 into Annual Revenue on Account';
rollupSummary.ParentObject__c = 'Account';
rollupSummary.ChildObject__c = 'Opportunity';
rollupSummary.RelationShipField__c = 'AccountId';
rollupSummary.RelationShipCriteria__c = null;
rollupSummary.FieldToAggregate__c = 'Amount';
rollupSummary.AggregateOperation__c = 'Sum';
rollupSummary.AggregateResultField__c = 'AnnualRevenue';
rollupSummary.Active__c = true;
rollupSummary.CalculationMode__c = 'Realtime';
insert new List<LookupRollupSummary__c> { rollupSummary };

// Test data
Account account = new Account();
account.Name = 'Test Account';
account.AnnualRevenue = 0;
insert account;
{
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Open';
opp.CloseDate = System.today();
opp.AccountId = account.Id;
opp.Amount = 100;
insert opp;
}
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Open';
opp.CloseDate = System.today();
opp.AccountId = account.Id;
opp.Amount = 100;
insert opp;

// Assert rollup
System.assertEquals(200, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue);

// Delete Opportunity
delete opp;

// Assert rollup
System.assertEquals(100, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue);
}

private testmethod static void testRollupWithoutChanges()
{
Expand Down

0 comments on commit 3c2f9ae

Please sign in to comment.