@@ -673,6 +673,53 @@ private class RollupIntegrationTests {
673
673
System .assertEquals (greatGrandparent .Name , updatedGreatGrandparent .Name , ' Great-grandparent name should not have been appended based on exclusions' );
674
674
}
675
675
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
+
676
723
@IsTest
677
724
static void shouldProperlyFilterPolymorphicWhatFields () {
678
725
Account acc = new Account (Name = ' Matching type' );
0 commit comments