@@ -1403,7 +1403,7 @@ private class RollupIntegrationTests {
1403
1403
Rollup .records = cpas ;
1404
1404
Rollup .shouldRun = true ;
1405
1405
Rollup .apexContext = TriggerOperation .AFTER_INSERT ;
1406
- Rollup .specificControl = new RollupControl__mdt (ShouldRunAs__c = ' Synchronous Rollup ' );
1406
+ Rollup .specificControl = new RollupControl__mdt (ShouldRunAs__c = RollupMetaPicklists . ShouldRunAs . Synchronous );
1407
1407
1408
1408
// specifically do NOT wrap in Test.startTest() / Test.stopTest() - we need to ensure this happened synchronously
1409
1409
Rollup .countFromApex (ContactPointAddress .PreferenceRank , ContactPointAddress .ParentId , Account .Id , Account .AnnualRevenue , Account .SObjectType ).runCalc ();
@@ -1414,7 +1414,6 @@ private class RollupIntegrationTests {
1414
1414
1415
1415
@IsTest
1416
1416
static void shouldPartiallyDeferRollupCalculationWhenOverLimits () {
1417
- Rollup .specificControl = new RollupControl__mdt (ShouldAbortRun__c = true );
1418
1417
Account acc = [SELECT Id , OwnerId FROM Account ];
1419
1418
Account secondParent = new Account (Name = ' Second parent' );
1420
1419
insert secondParent ;
@@ -1425,10 +1424,14 @@ private class RollupIntegrationTests {
1425
1424
};
1426
1425
insert cpas ;
1427
1426
1428
- Rollup .defaultControl = new RollupControl__mdt (BatchChunkSize__c = 1 , MaxRollupRetries__c = 1 , MaxNumberOfQueries__c = 2 , IsRollupLoggingEnabled__c = true );
1429
1427
// start as synchronous rollup to allow for one deferral
1430
- Rollup .specificControl = new RollupControl__mdt (ShouldRunAs__c = ' Synchronous Rollup' );
1431
-
1428
+ Rollup .defaultControl = new RollupControl__mdt (
1429
+ BatchChunkSize__c = 1 ,
1430
+ MaxRollupRetries__c = 1 ,
1431
+ MaxNumberOfQueries__c = 2 ,
1432
+ IsRollupLoggingEnabled__c = true ,
1433
+ ShouldRunAs__c = RollupMetaPicklists .ShouldRunAs .Synchronous
1434
+ );
1432
1435
Rollup .shouldRun = true ;
1433
1436
Rollup .records = cpas ;
1434
1437
Rollup .rollupMetadata = new List <Rollup__mdt >{
@@ -1460,6 +1463,71 @@ private class RollupIntegrationTests {
1460
1463
}
1461
1464
}
1462
1465
1466
+ @IsTest
1467
+ static void shouldNotBlowUpWhenDeferralLeadsToMultipleSObjectsBeingPresent () {
1468
+ Account acc = [SELECT Id , OwnerId FROM Account ];
1469
+
1470
+ Individual indy = new Individual (LastName = ' Indy' );
1471
+ insert indy ;
1472
+
1473
+ List <ContactPointAddress > cpas = new List <ContactPointAddress >{
1474
+ new ContactPointAddress (ParentId = acc .Id , Name = ' One' , PreferenceRank = 1 ),
1475
+ new ContactPointAddress (ParentId = indy .Id , Name = ' Two' , PreferenceRank = 1 )
1476
+ };
1477
+ insert cpas ;
1478
+
1479
+ Rollup .defaultControl = new RollupControl__mdt (
1480
+ BatchChunkSize__c = 2 ,
1481
+ MaxRollupRetries__c = 1 ,
1482
+ MaxNumberOfQueries__c = 2 ,
1483
+ IsRollupLoggingEnabled__c = true ,
1484
+ ShouldRunAs__c = RollupMetaPicklists .ShouldRunAs .Synchronous
1485
+ );
1486
+ RollupAsyncProcessor .shouldRunAsBatch = true ;
1487
+ Rollup .shouldRun = true ;
1488
+ Rollup .records = cpas ;
1489
+ Rollup .rollupMetadata = new List <Rollup__mdt >{
1490
+ new Rollup__mdt (
1491
+ CalcItem__c = ' ContactPointAddress' ,
1492
+ RollupFieldOnCalcItem__c = ' PreferenceRank' ,
1493
+ LookupFieldOnCalcItem__c = ' ParentId' ,
1494
+ LookupObject__c = ' Account' ,
1495
+ LookupFieldOnLookupObject__c = ' Id' ,
1496
+ RollupFieldOnLookupObject__c = ' AnnualRevenue' ,
1497
+ RollupOperation__c = ' AVERAGE'
1498
+ ),
1499
+ new Rollup__mdt (
1500
+ CalcItem__c = ' ContactPointAddress' ,
1501
+ RollupFieldOnCalcItem__c = ' PreferenceRank' ,
1502
+ LookupFieldOnCalcItem__c = ' ParentId' ,
1503
+ LookupObject__c = ' Individual' ,
1504
+ LookupFieldOnLookupObject__c = ' Id' ,
1505
+ RollupFieldOnLookupObject__c = ' ChildrenCount' ,
1506
+ RollupOperation__c = ' COUNT'
1507
+ ),
1508
+ new Rollup__mdt (
1509
+ CalcItem__c = ' ContactPointAddress' ,
1510
+ RollupFieldOnCalcItem__c = ' Name' ,
1511
+ LookupFieldOnCalcItem__c = ' ParentId' ,
1512
+ LookupObject__c = ' Individual' ,
1513
+ LookupFieldOnLookupObject__c = ' Id' ,
1514
+ RollupFieldOnLookupObject__c = ' LastName' ,
1515
+ RollupOperation__c = ' CONCAT'
1516
+ )
1517
+ };
1518
+ Rollup .apexContext = TriggerOperation .AFTER_INSERT ;
1519
+
1520
+ Test .startTest ();
1521
+ Rollup .runFromTrigger ();
1522
+ Test .stopTest ();
1523
+
1524
+ acc = [SELECT AnnualRevenue FROM Account ];
1525
+ indy = [SELECT LastName , ChildrenCount FROM Individual ];
1526
+ System .assertEquals (1 , acc .AnnualRevenue , ' Annual revenue should have been averaged properly' );
1527
+ System .assertEquals (1 , indy .ChildrenCount , ' Children count should have been counted correctly' );
1528
+ System .assertEquals (' Indy, Two' , indy .LastName , ' LastName should have been concat properly' );
1529
+ }
1530
+
1463
1531
@IsTest
1464
1532
static void shouldRunDirectlyFromApex () {
1465
1533
Account acc = [SELECT Id FROM Account ];
0 commit comments