|
1 | 1 | @IsTest
|
2 | 2 | private class CustomMetadataDrivenTests {
|
3 |
| - |
4 | 3 | @TestSetup
|
5 | 4 | static void setup() {
|
6 | 5 | upsert new RollupSettings__c(IsEnabled__c = true);
|
@@ -89,4 +88,36 @@ private class CustomMetadataDrivenTests {
|
89 | 88 | parent = [SELECT DateField__c FROM RollupParent__c WHERE Id = :parent.Id];
|
90 | 89 | System.assertEquals(childOne.DateField__c, parent.DateField__c);
|
91 | 90 | }
|
92 |
| -} |
| 91 | + |
| 92 | + @IsTest |
| 93 | + static void shouldRunCorrectlyForGrandparentReparenting() { |
| 94 | + Account greatGrandparent = new Account(Name = 'Great-grandparent'); |
| 95 | + Account secondGreatGrandparent = new Account(Name = 'Second great-grandparent'); |
| 96 | + insert new List<Account>{ greatGrandparent, secondGreatGrandparent }; |
| 97 | + |
| 98 | + ParentApplication__c grandParent = new ParentApplication__c(Name = 'Grandparent', Account__c = greatGrandparent.Id); |
| 99 | + ParentApplication__c secondGrandparent = new ParentApplication__c(Name = 'Second grandparent', Account__c = secondGreatGrandparent.Id); |
| 100 | + insert new List<ParentApplication__c>{ grandParent, secondGrandparent }; |
| 101 | + |
| 102 | + Application__c parent = new Application__c(Name = 'Parent-level', ParentApplication__c = grandParent.Id); |
| 103 | + Application__c secondParent = new Application__c(Name = 'Second parent-level', ParentApplication__c = secondGrandparent.Id); |
| 104 | + insert new List<Application__c>{ parent, secondParent }; |
| 105 | + |
| 106 | + ApplicationLog__c child = new ApplicationLog__c(Application__c = parent.Id, Name = greatGrandparent.Name); |
| 107 | + ApplicationLog__c secondChild = new ApplicationLog__c(Application__c = secondParent.Id, Name = secondGreatGrandparent.Name); |
| 108 | + insert new List<ApplicationLog__c>{ child, secondChild }; |
| 109 | + |
| 110 | + child = new ApplicationLog__c(Id = child.Id, Application__c = secondParent.Id, Name = 'Test Rollup Grandchildren Reparenting'); |
| 111 | + secondChild = new ApplicationLog__c(Id = secondChild.Id, Name = 'Reparenting deux', Application__c = parent.Id); |
| 112 | + |
| 113 | + Test.startTest(); |
| 114 | + update new List<ApplicationLog__c>{ child, secondChild }; |
| 115 | + Test.stopTest(); |
| 116 | + |
| 117 | + Account updatedGreatGrandparent = [SELECT Name FROM Account WHERE Id = :greatGrandparent.Id]; |
| 118 | + Account updatedGreatGrandparentTwo = [SELECT Name FROM Account WHERE Id = :secondGreatGrandparent.Id]; |
| 119 | + |
| 120 | + System.assertEquals(secondChild.Name, updatedGreatGrandparent.Name, 'CONCAT_DISTINCT and reparenting should have worked'); |
| 121 | + System.assertEquals(child.Name, updatedGreatGrandparentTwo.Name, 'CONCAT_DISTINCT and reparenting should have worked again'); |
| 122 | + } |
| 123 | +} |
0 commit comments