From 87f7102ae72f6aea24801a643da85b59b6f01663 Mon Sep 17 00:00:00 2001 From: Adair21 Date: Tue, 6 Jan 2015 10:35:37 -0600 Subject: [PATCH 1/8] Delete LookupRollupSummariesFull.permissionset --- .../LookupRollupSummariesFull.permissionset | 263 ------------------ 1 file changed, 263 deletions(-) delete mode 100644 rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset diff --git a/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset b/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset deleted file mode 100644 index c52943a0..00000000 --- a/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset +++ /dev/null @@ -1,263 +0,0 @@ - - - - ApexClassesSelector - false - - - ApexTriggersSelector - false - - - AsyncApexJobsSelector - false - - - LREngine - false - - - MetadataService - false - - - MetadataServiceTest - false - - - RollupCalculateController - false - - - RollupCalculateJob - false - - - RollupController - false - - - RollupControllerTest - false - - - RollupJob - false - - - RollupJobTest - false - - - RollupService - false - - - RollupServiceException - false - - - RollupServiceTest - false - - - RollupServiceTest2 - false - - - RollupServiceTest3 - false - - - RollupSummaries - false - - - RollupSummariesSelector - false - - - RollupSummariesTest - false - - - RollupSummaryEnhancedController - false - - - RollupSummaryEnhancedControllerTest - false - - - RollupSummaryScheduleItemsSelector - false - - - SObjectDomain - false - - - SObjectDomainTest - false - - - SObjectSelector - false - - - SObjectSelectorTest - false - - - StringBuilder - false - - - TestContext - false - - - TestLREngine - false - - - WelcomeController - false - - - WelcomeControllerTest - false - - Provides full configuration access to the rollup summaries. This enabled Author Apex and API access to enable it to deploy the necessary Triggers via the Manage Child Trigger button. - - false - LookupChild__c.Amount__c - false - - - false - LookupChild__c.LookupParent__c - false - - - false - LookupParent__c.Total__c - false - - - true - LookupRollupSummaryLog__c.ErrorMessage__c - true - - - true - LookupRollupSummaryLog__c.ParentObject__c - true - - - false - LookupRollupSummaryLog__c.ParentRecord__c - true - - - false - LookupRollupSummaryScheduleItems__c.ParentRecord__c - true - - - true - LookupRollupSummary__c.Active__c - true - - - true - LookupRollupSummary__c.AggregateOperation__c - true - - - true - LookupRollupSummary__c.CalculateJobId__c - true - - - true - LookupRollupSummary__c.CalculationMode__c - true - - - true - LookupRollupSummary__c.RelationshipCriteriaFields__c - true - - - true - LookupRollupSummary__c.RelationshipCriteria__c - true - - - - true - true - true - true - true - LookupChild__c - true - - - true - true - true - true - true - LookupParent__c - true - - - true - true - true - true - true - LookupRollupSummaryLog__c - true - - - true - true - true - true - true - LookupRollupSummaryScheduleItems__c - true - - - true - true - true - true - true - LookupRollupSummary__c - true - - - managetrigger - true - - - rollupcalculate - true - - - rollupsummaryenhanced - true - - - rollupsummaryenhancednew - true - - - welcome - true - - From b00535760893678ca03d7f9cb8d59643759075da Mon Sep 17 00:00:00 2001 From: Adair21 Date: Tue, 6 Jan 2015 10:35:45 -0600 Subject: [PATCH 2/8] Delete LookupRollupSummariesReadOnly.permissionset --- ...ookupRollupSummariesReadOnly.permissionset | 250 ------------------ 1 file changed, 250 deletions(-) delete mode 100644 rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset diff --git a/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset b/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset deleted file mode 100644 index b1f8e072..00000000 --- a/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset +++ /dev/null @@ -1,250 +0,0 @@ - - - - ApexClassesSelector - false - - - ApexTriggersSelector - false - - - AsyncApexJobsSelector - false - - - LREngine - false - - - MetadataService - false - - - MetadataServiceTest - false - - - RollupCalculateController - false - - - RollupCalculateJob - false - - - RollupController - false - - - RollupControllerTest - false - - - RollupJob - false - - - RollupJobTest - false - - - RollupService - false - - - RollupServiceException - false - - - RollupServiceTest - false - - - RollupServiceTest2 - false - - - RollupServiceTest3 - false - - - RollupSummaries - false - - - RollupSummariesSelector - false - - - RollupSummariesTest - false - - - RollupSummaryEnhancedController - false - - - RollupSummaryEnhancedControllerTest - false - - - RollupSummaryScheduleItemsSelector - false - - - SObjectDomain - false - - - SObjectDomainTest - false - - - SObjectSelector - false - - - SObjectSelectorTest - false - - - StringBuilder - false - - - TestContext - false - - - TestLREngine - false - - - WelcomeController - false - - - WelcomeControllerTest - false - - Grant this permission set to end users that indirectly cause the rollup summaries to be executed. Such users can only read the rollup summary definitions, logs and scheduled entires. - - false - LookupChild__c.Amount__c - false - - - false - LookupChild__c.LookupParent__c - false - - - false - LookupParent__c.Total__c - false - - - false - LookupRollupSummaryLog__c.ErrorMessage__c - true - - - false - LookupRollupSummaryLog__c.ParentObject__c - true - - - false - LookupRollupSummaryLog__c.ParentRecord__c - true - - - true - LookupRollupSummaryScheduleItems__c.ParentId__c - true - - - false - LookupRollupSummaryScheduleItems__c.ParentRecord__c - true - - - false - LookupRollupSummary__c.Active__c - true - - - false - LookupRollupSummary__c.AggregateOperation__c - true - - - false - LookupRollupSummary__c.CalculateJobId__c - true - - - false - LookupRollupSummary__c.CalculationMode__c - true - - - false - LookupRollupSummary__c.RelationshipCriteriaFields__c - true - - - false - LookupRollupSummary__c.RelationshipCriteria__c - true - - - - false - false - false - true - false - LookupRollupSummaryLog__c - false - - - false - false - false - true - false - LookupRollupSummaryScheduleItems__c - false - - - false - false - false - true - false - LookupRollupSummary__c - false - - - managetrigger - false - - - rollupcalculate - false - - - rollupsummaryenhanced - false - - - rollupsummaryenhancednew - false - - - welcome - false - - From 4797dedc3ce5c0b3dda92c04928e6c360a731601 Mon Sep 17 00:00:00 2001 From: Adair21 Date: Tue, 6 Jan 2015 10:52:07 -0600 Subject: [PATCH 3/8] Revert "Delete LookupRollupSummariesFull.permissionset" This reverts commit 87f7102ae72f6aea24801a643da85b59b6f01663. --- .../LookupRollupSummariesFull.permissionset | 263 ++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset diff --git a/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset b/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset new file mode 100644 index 00000000..c52943a0 --- /dev/null +++ b/rolluptool/src/permissionsets/LookupRollupSummariesFull.permissionset @@ -0,0 +1,263 @@ + + + + ApexClassesSelector + false + + + ApexTriggersSelector + false + + + AsyncApexJobsSelector + false + + + LREngine + false + + + MetadataService + false + + + MetadataServiceTest + false + + + RollupCalculateController + false + + + RollupCalculateJob + false + + + RollupController + false + + + RollupControllerTest + false + + + RollupJob + false + + + RollupJobTest + false + + + RollupService + false + + + RollupServiceException + false + + + RollupServiceTest + false + + + RollupServiceTest2 + false + + + RollupServiceTest3 + false + + + RollupSummaries + false + + + RollupSummariesSelector + false + + + RollupSummariesTest + false + + + RollupSummaryEnhancedController + false + + + RollupSummaryEnhancedControllerTest + false + + + RollupSummaryScheduleItemsSelector + false + + + SObjectDomain + false + + + SObjectDomainTest + false + + + SObjectSelector + false + + + SObjectSelectorTest + false + + + StringBuilder + false + + + TestContext + false + + + TestLREngine + false + + + WelcomeController + false + + + WelcomeControllerTest + false + + Provides full configuration access to the rollup summaries. This enabled Author Apex and API access to enable it to deploy the necessary Triggers via the Manage Child Trigger button. + + false + LookupChild__c.Amount__c + false + + + false + LookupChild__c.LookupParent__c + false + + + false + LookupParent__c.Total__c + false + + + true + LookupRollupSummaryLog__c.ErrorMessage__c + true + + + true + LookupRollupSummaryLog__c.ParentObject__c + true + + + false + LookupRollupSummaryLog__c.ParentRecord__c + true + + + false + LookupRollupSummaryScheduleItems__c.ParentRecord__c + true + + + true + LookupRollupSummary__c.Active__c + true + + + true + LookupRollupSummary__c.AggregateOperation__c + true + + + true + LookupRollupSummary__c.CalculateJobId__c + true + + + true + LookupRollupSummary__c.CalculationMode__c + true + + + true + LookupRollupSummary__c.RelationshipCriteriaFields__c + true + + + true + LookupRollupSummary__c.RelationshipCriteria__c + true + + + + true + true + true + true + true + LookupChild__c + true + + + true + true + true + true + true + LookupParent__c + true + + + true + true + true + true + true + LookupRollupSummaryLog__c + true + + + true + true + true + true + true + LookupRollupSummaryScheduleItems__c + true + + + true + true + true + true + true + LookupRollupSummary__c + true + + + managetrigger + true + + + rollupcalculate + true + + + rollupsummaryenhanced + true + + + rollupsummaryenhancednew + true + + + welcome + true + + From bccda09de6738f1fdd11378ce8c314da60ea972d Mon Sep 17 00:00:00 2001 From: Adair21 Date: Tue, 6 Jan 2015 10:52:15 -0600 Subject: [PATCH 4/8] Revert "Delete LookupRollupSummariesReadOnly.permissionset" This reverts commit b00535760893678ca03d7f9cb8d59643759075da. --- ...ookupRollupSummariesReadOnly.permissionset | 250 ++++++++++++++++++ 1 file changed, 250 insertions(+) create mode 100644 rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset diff --git a/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset b/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset new file mode 100644 index 00000000..b1f8e072 --- /dev/null +++ b/rolluptool/src/permissionsets/LookupRollupSummariesReadOnly.permissionset @@ -0,0 +1,250 @@ + + + + ApexClassesSelector + false + + + ApexTriggersSelector + false + + + AsyncApexJobsSelector + false + + + LREngine + false + + + MetadataService + false + + + MetadataServiceTest + false + + + RollupCalculateController + false + + + RollupCalculateJob + false + + + RollupController + false + + + RollupControllerTest + false + + + RollupJob + false + + + RollupJobTest + false + + + RollupService + false + + + RollupServiceException + false + + + RollupServiceTest + false + + + RollupServiceTest2 + false + + + RollupServiceTest3 + false + + + RollupSummaries + false + + + RollupSummariesSelector + false + + + RollupSummariesTest + false + + + RollupSummaryEnhancedController + false + + + RollupSummaryEnhancedControllerTest + false + + + RollupSummaryScheduleItemsSelector + false + + + SObjectDomain + false + + + SObjectDomainTest + false + + + SObjectSelector + false + + + SObjectSelectorTest + false + + + StringBuilder + false + + + TestContext + false + + + TestLREngine + false + + + WelcomeController + false + + + WelcomeControllerTest + false + + Grant this permission set to end users that indirectly cause the rollup summaries to be executed. Such users can only read the rollup summary definitions, logs and scheduled entires. + + false + LookupChild__c.Amount__c + false + + + false + LookupChild__c.LookupParent__c + false + + + false + LookupParent__c.Total__c + false + + + false + LookupRollupSummaryLog__c.ErrorMessage__c + true + + + false + LookupRollupSummaryLog__c.ParentObject__c + true + + + false + LookupRollupSummaryLog__c.ParentRecord__c + true + + + true + LookupRollupSummaryScheduleItems__c.ParentId__c + true + + + false + LookupRollupSummaryScheduleItems__c.ParentRecord__c + true + + + false + LookupRollupSummary__c.Active__c + true + + + false + LookupRollupSummary__c.AggregateOperation__c + true + + + false + LookupRollupSummary__c.CalculateJobId__c + true + + + false + LookupRollupSummary__c.CalculationMode__c + true + + + false + LookupRollupSummary__c.RelationshipCriteriaFields__c + true + + + false + LookupRollupSummary__c.RelationshipCriteria__c + true + + + + false + false + false + true + false + LookupRollupSummaryLog__c + false + + + false + false + false + true + false + LookupRollupSummaryScheduleItems__c + false + + + false + false + false + true + false + LookupRollupSummary__c + false + + + managetrigger + false + + + rollupcalculate + false + + + rollupsummaryenhanced + false + + + rollupsummaryenhancednew + false + + + welcome + false + + From 26369de8cb3d1f89ce2bf9e9df97223d12cd133a Mon Sep 17 00:00:00 2001 From: Adair21 Date: Tue, 6 Jan 2015 10:53:46 -0600 Subject: [PATCH 5/8] Update package.xml Removed permissions sets in order to be able to deploy --- rolluptool/src/package.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/rolluptool/src/package.xml b/rolluptool/src/package.xml index 30281da0..8fe2486a 100644 --- a/rolluptool/src/package.xml +++ b/rolluptool/src/package.xml @@ -79,11 +79,6 @@ LookupRollupSummary__c-Lookup Rollup Summary Layout Layout - - LookupRollupSummariesFull - LookupRollupSummariesReadOnly - PermissionSet - jszip StaticResource From c0c2bc94e93148e6c630e298bfbecc4d157d733a Mon Sep 17 00:00:00 2001 From: Adair21 Date: Wed, 7 Jan 2015 11:38:32 -0600 Subject: [PATCH 6/8] Update RollupServiceTest.cls Added test case for 10 chunks during database operation: https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/58 --- rolluptool/src/classes/RollupServiceTest.cls | 98 +++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-) diff --git a/rolluptool/src/classes/RollupServiceTest.cls b/rolluptool/src/classes/RollupServiceTest.cls index e79447ab..98ce8dc0 100644 --- a/rolluptool/src/classes/RollupServiceTest.cls +++ b/rolluptool/src/classes/RollupServiceTest.cls @@ -432,6 +432,102 @@ private with sharing class RollupServiceTest System.assertEquals(expectedResultC, campResult.get('NumberSent')); } + private testmethod static void testMultiRollupWithTwoParentsTenChunks() + { + // Test supported? + if(!TestContext.isSupported()) + return; + + // Test data + List rollups = new List { + 1, 2, 3, 4, 5 + ,6, 7, 8, 9, 10 + ,11, 12, 13, 14, 15 + }; + + // Test data for rollup A + RollupSummaries.AggregateOperation operationA = RollupSummaries.AggregateOperation.Sum; + String conditionA = null; + + // Test data for rollup B + RollupSummaries.AggregateOperation operationC = RollupSummaries.AggregateOperation.Sum; + String conditionB = null; + + // Configure rollup A + LookupRollupSummary__c rollupSummaryA = new LookupRollupSummary__c(); + rollupSummaryA.Name = 'Total Opportunities greater than 200 into Annual Revenue on Account'; + rollupSummaryA.ParentObject__c = 'Account'; + rollupSummaryA.ChildObject__c = 'Opportunity'; + rollupSummaryA.RelationShipField__c = 'AccountId'; + rollupSummaryA.RelationShipCriteria__c = conditionA; + rollupSummaryA.FieldToAggregate__c = 'Amount'; + rollupSummaryA.AggregateOperation__c = operationA.name(); + rollupSummaryA.AggregateResultField__c = 'AnnualRevenue'; + rollupSummaryA.Active__c = true; + rollupSummaryA.CalculationMode__c = 'Realtime'; + + // Configure rollup B + LookupRollupSummary__c rollupSummaryB = new LookupRollupSummary__c(); + rollupSummaryB.Name = 'Total Opportunities into Num Sent on Campaign'; + rollupSummaryB.ParentObject__c = 'Campaign'; + rollupSummaryB.ChildObject__c = 'Opportunity'; + rollupSummaryB.RelationShipField__c = 'CampaignId'; + rollupSummaryB.RelationShipCriteria__c = conditionB; + rollupSummaryB.FieldToAggregate__c = 'TotalOpportunityQuantity'; + rollupSummaryB.AggregateOperation__c = operationC.name(); + rollupSummaryB.AggregateResultField__c = 'NumberSent'; + rollupSummaryB.Active__c = true; + rollupSummaryB.CalculationMode__c = 'Realtime'; + + // Insert rollup definitions + insert new List { rollupSummaryA, rollupSummaryB }; + + // Test data + List accountList = new List(); + List campaignList = new List(); + + List opps = new List(); + Integer index = 0; + for(Decimal rollupValue : rollups) { + // add each Opportunity to a new Account/Campaign to produce chunking + accountList.add(new Account()); + accountList[index].put('Name', 'Test Account'); + accountList[index].put('AnnualRevenue', 0); + insert accountList[index]; + + campaignList.add( Schema.getGlobalDescribe().get('Campaign').newSObject() ); + campaignList[index].put('Name', 'Test Campaign'); + insert campaignList[index]; + + Opportunity opp = new Opportunity(); + opp.Name = 'Test Opportunity'; + opp.StageName = 'Open'; + opp.CloseDate = System.today(); + opp.AccountId = accountList[index].Id; + opp.Amount = rollupValue; + opp.TotalOpportunityQuantity = rollupValue; + opp.put('CampaignId', campaignList[index].Id); + opps.add(opp); + + index++; + } + insert opps; + + // Assert rollups for each Account/Campaign + index = 0; + for(Decimal rollupValue : rollups) { + Id accountId = accountList[index].Id; + Account accountResult = Database.query('select AnnualRevenue, NumberOfLocations__c from Account where Id = :accountId'); + System.assertEquals(rollupValue, accountResult.AnnualRevenue); + + Id campId = campaignList[index].Id; + SObject campResult = Database.query('select NumberSent from Campaign where Id = :campId'); + System.assertEquals(rollupValue, campResult.get('NumberSent')); + + index++; + } + } + private testmethod static void testSingleRollupWithoutRelation() { // Test supported? @@ -876,4 +972,4 @@ private with sharing class RollupServiceTest // Assert rollup System.assertEquals(expectedResult, [select AnnualRevenue from Account where Id = :account.Id].AnnualRevenue); } -} \ No newline at end of file +} From 14703ad14bfa0def832144c0a594a6a165fa9900 Mon Sep 17 00:00:00 2001 From: Adair21 Date: Wed, 7 Jan 2015 11:40:29 -0600 Subject: [PATCH 7/8] Update RollupService.cls Bug fix for case when masterRecords contains more than 10 chunks: https://github.com/afawcett/declarative-lookup-rollup-summaries/issues/58 --- rolluptool/src/classes/RollupService.cls | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rolluptool/src/classes/RollupService.cls b/rolluptool/src/classes/RollupService.cls index 6c835336..128f4218 100644 --- a/rolluptool/src/classes/RollupService.cls +++ b/rolluptool/src/classes/RollupService.cls @@ -604,6 +604,20 @@ global with sharing class RollupService public virtual List updateRecords(boolean allOrNothing) { + // sort (selection sort) masterRecords to avoid having more than 10 chunks in a single database operation + // masterRecords.sort() will not work + Integer indexOfMin; + for( Integer outerIndex = 0; outerIndex < masterRecords.size(); outerIndex++ ){ + indexOfMin = outerIndex; + for( Integer innerIndex = outerIndex; innerIndex < masterRecords.size(); innerIndex++ ){ + if( String.valueOf(masterRecords.get(indexOfMin).getSObjectType()).compareTo( String.valueOf(masterRecords.get(innerIndex).getSObjectType()) ) > 0 ){ + indexOfMin = innerIndex; + } + } + SObject temp = masterRecords.get(outerIndex); + masterRecords.set( outerIndex, masterRecords.get(indexOfMin) ); + masterRecords.set(indexOfMin, temp); + } return Database.update(masterRecords, allOrNothing); } } @@ -625,4 +639,4 @@ global with sharing class RollupService public override List updateRecords(boolean allOrNothing) { return super.updateRecords(allOrNothing); } } -} \ No newline at end of file +} From 7ddea7a55162b5c93027df09279b5d79d439667b Mon Sep 17 00:00:00 2001 From: Adair21 Date: Wed, 7 Jan 2015 13:13:35 -0600 Subject: [PATCH 8/8] Revert "Update package.xml" This reverts commit 26369de8cb3d1f89ce2bf9e9df97223d12cd133a. --- rolluptool/src/package.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rolluptool/src/package.xml b/rolluptool/src/package.xml index 8fe2486a..30281da0 100644 --- a/rolluptool/src/package.xml +++ b/rolluptool/src/package.xml @@ -79,6 +79,11 @@ LookupRollupSummary__c-Lookup Rollup Summary Layout Layout + + LookupRollupSummariesFull + LookupRollupSummariesReadOnly + PermissionSet + jszip StaticResource