Skip to content

Commit b7cafd8

Browse files
authored
v1.6.22 - Grandparent COUNT_DISTINCT deletion bugfix (#582)
* Fixes #581 by properly handling COUNT_DISTINCT for grandparent rollup deletions
1 parent 936c135 commit b7cafd8

File tree

9 files changed

+64
-11
lines changed

9 files changed

+64
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ As well, don't miss [the Wiki](../../wiki), which includes even more info for co
2424

2525
## Deployment & Setup
2626

27-
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OatsAAC">
27+
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavAAAS">
2828
<img alt="Deploy to Salesforce"
2929
src="./media/deploy-package-to-prod.png">
3030
</a>
3131

32-
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OatsAAC">
32+
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavAAAS">
3333
<img alt="Deploy to Salesforce Sandbox"
3434
src="./media/deploy-package-to-sandbox.png">
3535
</a>

extra-tests/classes/RollupIntegrationTests.cls

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,53 @@ private class RollupIntegrationTests {
673673
System.assertEquals(greatGrandparent.Name, updatedGreatGrandparent.Name, 'Great-grandparent name should not have been appended based on exclusions');
674674
}
675675

676+
@IsTest
677+
static void shouldCountDistinctForGrandparentDeletes() {
678+
if (RollupTestUtils.IS_NAMESPACED_PACKAGE_ORG) {
679+
return;
680+
}
681+
682+
Rollup.onlyUseMockMetadata = true;
683+
Rollup.shouldFlattenAsyncProcesses = true;
684+
Rollup.rollupMetadata = new List<Rollup__mdt>{
685+
new Rollup__mdt(
686+
CalcItem__c = ApplicationLog__c.SObjectType.getDescribe(SObjectDescribeOptions.DEFERRED).getName(),
687+
RollupFieldOnCalcItem__c = 'Name',
688+
LookupFieldOnCalcItem__c = ApplicationLog__c.Application__c.getDescribe().getName(),
689+
LookupObject__c = 'Account',
690+
LookupFieldOnLookupObject__c = 'Id',
691+
RollupFieldOnLookupObject__c = 'AnnualRevenue',
692+
RollupOperation__c = 'COUNT_DISTINCT',
693+
GrandparentRelationshipFieldPath__c = RollupTestUtils.getRelationshipPath(
694+
new List<Schema.SObjectField>{ ApplicationLog__c.Application__c, Application__c.ParentApplication__c, ParentApplication__c.Account__c, Account.Name }
695+
)
696+
)
697+
};
698+
699+
Account greatGrandparent = new Account(Name = 'Great-grandparent 1');
700+
insert greatGrandparent;
701+
702+
ParentApplication__c grandParent = new ParentApplication__c(Name = 'Grandparent 1', Account__c = greatGrandparent.Id);
703+
ParentApplication__c secondGrandparent = new ParentApplication__c(Name = 'Grandparent 2', Account__c = greatGrandparent.Id);
704+
List<ParentApplication__c> parentApps = new List<ParentApplication__c>{ grandParent, secondGrandparent };
705+
insert parentApps;
706+
707+
Application__c parent = new Application__c(Name = 'Parent 1', ParentApplication__c = grandParent.Id);
708+
Application__c secondParent = new Application__c(Name = 'Parent 2', ParentApplication__c = secondGrandparent.Id);
709+
insert new List<Application__c>{ parent, secondParent };
710+
711+
ApplicationLog__c child = new ApplicationLog__c(Application__c = secondParent.Id, Name = 'Will Still Exist');
712+
ApplicationLog__c secondChild = new ApplicationLog__c(Name = 'To be deleted', Application__c = parent.Id);
713+
insert new List<ApplicationLog__c>{ child, secondChild };
714+
715+
Test.startTest();
716+
delete secondChild;
717+
Test.stopTest();
718+
719+
greatGrandparent = [SELECT AnnualRevenue FROM Account WHERE Id = :greatGrandparent.Id];
720+
Assert.areEqual(1, greatGrandparent.AnnualRevenue, 'Should still count non-deleted great-grandchild');
721+
}
722+
676723
@IsTest
677724
static void shouldProperlyFilterPolymorphicWhatFields() {
678725
Account acc = new Account(Name = 'Matching type');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apex-rollup",
3-
"version": "1.6.21",
3+
"version": "1.6.22",
44
"description": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
55
"repository": {
66
"type": "git",

rollup-namespaced/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ For more info, see the base `README`.
1818

1919
## Deployment & Setup
2020

21-
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OatxAAC">
21+
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavFAAS">
2222
<img alt="Deploy to Salesforce"
2323
src="./media/deploy-package-to-prod.png">
2424
</a>
2525

26-
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OatxAAC">
26+
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavFAAS">
2727
<img alt="Deploy to Salesforce Sandbox"
2828
src="./media/deploy-package-to-sandbox.png">
2929
</a>

rollup-namespaced/sfdx-project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"[email protected]": "04t6g000008OaYwAAK",
2626
"[email protected]": "04t6g000008OaZBAA0",
2727
"[email protected]": "04t6g000008OaZaAAK",
28-
"[email protected]": "04t6g000008OatxAAC"
28+
"[email protected]": "04t6g000008OavFAAS"
2929
}
3030
}

rollup/core/classes/RollupAsyncProcessor.cls

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,9 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
586586
// calling clear in a loop here might look interesting - and it would be a massive problem if not for the
587587
// bag only responding to the very first clear() invocation. everything after that is a no-op (so, any rollup with more
588588
// than one rollup operation going at a time)
589-
if (rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE || rollup.op.name().contains('DELETE')) {
589+
if (
590+
(rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE || rollup.op.name().contains('DELETE')) && rollup.traversal?.getIsFinished() != true
591+
) {
590592
bag.clear();
591593
}
592594
}

rollup/core/classes/RollupLogger.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
global without sharing virtual class RollupLogger implements ILogger {
22
@TestVisible
33
// this gets updated via the pipeline as the version number gets incremented
4-
private static final String CURRENT_VERSION_NUMBER = 'v1.6.21';
4+
private static final String CURRENT_VERSION_NUMBER = 'v1.6.22';
55
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
66
private static final RollupPlugin PLUGIN = new RollupPlugin();
77

rollup/core/classes/RollupRelationshipFieldFinder.cls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ public without sharing class RollupRelationshipFieldFinder {
654654
.setArg(inclusiveIds)
655655
.setArg(bindVar, this.records)
656656
.get();
657+
if (this.metadata.RollupOperation__c.contains('DELETE')) {
658+
this.records.clear();
659+
}
657660
this.records.addAll(additionalCalcItems);
658661
return additionalCalcItems;
659662
} catch (Exception ex) {

sfdx-project.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"package": "apex-rollup",
66
"path": "rollup",
77
"scopeProfiles": true,
8-
"versionName": "Updating to null coalesce operator when applicable",
9-
"versionNumber": "1.6.21.0",
8+
"versionName": "Fixes grandparent rollup logic for deletes with COUNT_DISTINCT",
9+
"versionNumber": "1.6.22.0",
1010
"versionDescription": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
1111
"releaseNotesUrl": "https://github.com/jamessimone/apex-rollup/releases/latest",
1212
"unpackagedMetadata": {
@@ -104,6 +104,7 @@
104104
"[email protected]": "04t6g000008Oak1AAC",
105105
"[email protected]": "04t6g000008Oal4AAC",
106106
"[email protected]": "04t6g000008OanPAAS",
107-
"[email protected]": "04t6g000008OatsAAC"
107+
"[email protected]": "04t6g000008OatsAAC",
108+
"[email protected]": "04t6g000008OavAAAS"
108109
}
109110
}

0 commit comments

Comments
 (0)