-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for 'Invalid Id' issue with scheduled rollups
See #1 85
- Loading branch information
1 parent
384f9f4
commit c7f6cab
Showing
9 changed files
with
213 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>31.0</apiVersion> | ||
<apiVersion>32.0</apiVersion> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* Copyright (c) 2013, Andrew Fawcett | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* - Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* - Neither the name of the Andrew Fawcett, nor the names of its contributors | ||
* may be used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
**/ | ||
|
||
@IsTest | ||
private class RollupServiceTest5 { | ||
|
||
@IsTest | ||
private static void testPolymorphicRelationshipsRealtime() { | ||
|
||
// Polymorphic lookup between Task and Account | ||
LookupRollupSummary__c rollupSummaryA = new LookupRollupSummary__c(); | ||
rollupSummaryA.Name = 'Test Rollup'; | ||
rollupSummaryA.ParentObject__c = 'Account'; | ||
rollupSummaryA.ChildObject__c = 'Task'; | ||
rollupSummaryA.RelationShipField__c = 'WhatId'; | ||
rollupSummaryA.FieldToAggregate__c = 'Id'; | ||
rollupSummaryA.AggregateOperation__c = RollupSummaries.AggregateOperation.Count.name(); | ||
rollupSummaryA.AggregateResultField__c = 'AnnualRevenue'; | ||
rollupSummaryA.Active__c = true; | ||
rollupSummaryA.CalculationMode__c = 'Realtime'; | ||
insert rollupSummaryA; | ||
|
||
// Polymorphic lookup between Task and Opportunity | ||
LookupRollupSummary__c rollupSummary = new LookupRollupSummary__c(); | ||
rollupSummary.Name = 'Test Rollup'; | ||
rollupSummary.ParentObject__c = 'Opportunity'; | ||
rollupSummary.ChildObject__c = 'Task'; | ||
rollupSummary.RelationShipField__c = 'WhatId'; | ||
rollupSummary.FieldToAggregate__c = 'Id'; | ||
rollupSummary.AggregateOperation__c = RollupSummaries.AggregateOperation.Count.name(); | ||
rollupSummary.AggregateResultField__c = 'TotalOpportunityQuantity'; | ||
rollupSummary.Active__c = true; | ||
rollupSummary.CalculationMode__c = 'Realtime'; | ||
insert rollupSummary; | ||
|
||
// Setup parent test records | ||
Account accountParent = new Account(Name = 'Test Account'); | ||
insert accountParent; | ||
Opportunity opp = new Opportunity(); | ||
opp.Name = 'Test Opportunity'; | ||
opp.StageName = 'Open'; | ||
opp.CloseDate = System.today(); | ||
opp.AccountId = accountParent.Id; | ||
insert opp; | ||
|
||
// Insert a Task for Account and assert | ||
Task task1 = new Task(); | ||
task1.Subject = 'Task A'; | ||
task1.WhatId = accountParent.Id; | ||
insert task1; | ||
System.assertEquals(1, [select AnnualRevenue from Account where id = :accountParent.Id][0].AnnualRevenue); | ||
System.assertEquals(null, [select TotalOpportunityQuantity from Opportunity where id = :opp.Id][0].TotalOpportunityQuantity); | ||
|
||
// Insert a Task for Oppoortunity and assert | ||
Task task2 = new Task(); | ||
task2.Subject = 'Task A'; | ||
task2.WhatId = opp.Id; | ||
insert task2; | ||
System.assertEquals(1, [select AnnualRevenue from Account where id = :accountParent.Id][0].AnnualRevenue); | ||
System.assertEquals(1, [select TotalOpportunityQuantity from Opportunity where id = :opp.Id][0].TotalOpportunityQuantity); | ||
} | ||
|
||
@IsTest | ||
private static void testPolymorphicRelationshipsScheduled() { | ||
|
||
// Polymorphic lookup between Task and Account | ||
LookupRollupSummary__c rollupSummaryAccount = new LookupRollupSummary__c(); | ||
rollupSummaryAccount.Name = 'Test Rollup'; | ||
rollupSummaryAccount.ParentObject__c = 'Account'; | ||
rollupSummaryAccount.ChildObject__c = 'Task'; | ||
rollupSummaryAccount.RelationShipField__c = 'WhatId'; | ||
rollupSummaryAccount.FieldToAggregate__c = 'Id'; | ||
rollupSummaryAccount.AggregateOperation__c = RollupSummaries.AggregateOperation.Count.name(); | ||
rollupSummaryAccount.AggregateResultField__c = 'AnnualRevenue'; | ||
rollupSummaryAccount.Active__c = true; | ||
rollupSummaryAccount.CalculationMode__c = 'Scheduled'; | ||
insert rollupSummaryAccount; | ||
|
||
// Polymorphic lookup between Task and Opportunity | ||
LookupRollupSummary__c rollupSummaryOpp = new LookupRollupSummary__c(); | ||
rollupSummaryOpp.Name = 'Test Rollup'; | ||
rollupSummaryOpp.ParentObject__c = 'Opportunity'; | ||
rollupSummaryOpp.ChildObject__c = 'Task'; | ||
rollupSummaryOpp.RelationShipField__c = 'WhatId'; | ||
rollupSummaryOpp.FieldToAggregate__c = 'Id'; | ||
rollupSummaryOpp.AggregateOperation__c = RollupSummaries.AggregateOperation.Count.name(); | ||
rollupSummaryOpp.AggregateResultField__c = 'TotalOpportunityQuantity'; | ||
rollupSummaryOpp.Active__c = true; | ||
rollupSummaryOpp.CalculationMode__c = 'Scheduled'; | ||
insert rollupSummaryOpp; | ||
|
||
// Setup parent test records | ||
Account accountParent = new Account(Name = 'Test Account'); | ||
insert accountParent; | ||
Opportunity oppParent = new Opportunity(); | ||
oppParent.Name = 'Test Opportunity'; | ||
oppParent.StageName = 'Open'; | ||
oppParent.CloseDate = System.today(); | ||
oppParent.AccountId = accountParent.Id; | ||
insert oppParent; | ||
|
||
// Insert Tasks to generated scheduled job work items | ||
Task task1 = new Task(); | ||
task1.Subject = 'Task A'; | ||
task1.WhatId = accountParent.Id; | ||
Task task2 = new Task(); | ||
task2.Subject = 'Task A'; | ||
task2.WhatId = oppParent.Id; | ||
insert new List<Task> { task1, task2 }; | ||
|
||
// Should have two scheduled job work items | ||
System.assertEquals(2, [select Id from LookupRollupSummaryScheduleItems__c].size()); // Assert a scheduled item has been created | ||
System.assertEquals(rollupSummaryAccount.Id, [select LookupRollupSummary__c from LookupRollupSummaryScheduleItems__c where ParentId__c = :accountParent.Id][0].LookupRollupSummary__c); | ||
System.assertEquals(rollupSummaryOpp.Id, [select LookupRollupSummary__c from LookupRollupSummaryScheduleItems__c where ParentId__c = :oppParent.Id][0].LookupRollupSummary__c); | ||
|
||
// Run rollup job | ||
Test.startTest(); | ||
RollupService.runJobToProcessScheduledItems(); | ||
Test.stopTest(); | ||
|
||
// Assert scheduled rollup job did its thing! | ||
System.assertEquals(1, [select AnnualRevenue from Account where id = :accountParent.Id][0].AnnualRevenue); | ||
System.assertEquals(1, [select TotalOpportunityQuantity from Opportunity where id = :oppParent.Id][0].TotalOpportunityQuantity); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>31.0</apiVersion> | ||
</ApexClass> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* NOTE: DO NOT PACKAGE THIS TRIGGER | ||
**/ | ||
|
||
/** | ||
* Auto Generated and Deployed by the Declarative Lookup Rollup Summaries Tool package (dlrs) | ||
**/ | ||
trigger RollupServiceTest4Trigger on Task | ||
(before delete, before insert, before update, after delete, after insert, after undelete, after update) | ||
{ | ||
RollupService.triggerHandler(); | ||
} |
5 changes: 5 additions & 0 deletions
5
rolluptool/src/triggers/RollupServiceTest4Trigger.trigger-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ApexTrigger xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>32.0</apiVersion> | ||
<status>Active</status> | ||
</ApexTrigger> |