@@ -1307,9 +1307,29 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
1307
1307
}
1308
1308
1309
1309
global static void runFromTrigger () {
1310
- SObjectType sObjectType = getTriggerRecords ().getSObjectType ();
1311
- List <Rollup__mdt > rollupMetadata = getTriggerRollupMetadata (sObjectType );
1312
- runFromApex (rollupMetadata , null , getTriggerRecords (), getOldTriggerRecordsMap ()).runCalc ();
1310
+ List <SObject > triggerRecords = getTriggerRecords ();
1311
+ List <Rollup__mdt > rollupMetadata = getTriggerRollupMetadata (triggerRecords .getSObjectType ());
1312
+ runFromApex (rollupMetadata , null , triggerRecords , getOldTriggerRecordsMap ()).runCalc ();
1313
+ }
1314
+
1315
+ /**
1316
+ * @param `List<SObject>` calcItems - the records whose values you'd like to roll up
1317
+ * @param `TriggerOperation` rollupContext - acceptable values are:
1318
+ * - TriggerOperation.AFTER_INSERT
1319
+ * - TriggerOperation.AFTER_UDATE
1320
+ * - TriggerOperation.BEFORE_DELETE
1321
+ * - TriggerOperation.AFTER_UNDELETE
1322
+ */
1323
+ global static void runFromApex (List <SObject > calcItems , TriggerOperation rollupContext ) {
1324
+ shouldRun = true ;
1325
+ records = calcItems ;
1326
+ apexContext = rollupContext ;
1327
+
1328
+ runFromTrigger ();
1329
+
1330
+ records = null ;
1331
+ shouldRun = null ;
1332
+ apexContext = null ;
1313
1333
}
1314
1334
1315
1335
private static Rollup runFromApex (List <Rollup__mdt > rollupMetadata , Evaluator eval , List <SObject > calcItems , Map <Id , SObject > oldCalcItems ) {
@@ -1437,14 +1457,14 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
1437
1457
SELECT
1438
1458
// we have to do transforms on these fields because custom objects/custom fields
1439
1459
// have references that otherwise won't work with the rest of the code
1440
- LookupObject__c ,
1460
+ LookupObject__c ,
1441
1461
LookupObject__r.QualifiedApiName ,
1442
- CalcItem__c ,
1462
+ CalcItem__c ,
1443
1463
CalcItem__r.QualifiedApiName ,
1444
1464
RollupFieldOnCalcItem__c ,
1445
1465
RollupFieldOnCalcItem__r.QualifiedApiName ,
1446
- LookupFieldOnCalcItem__c ,
1447
- LookupFieldOnCalcItem__r.QualifiedApiName ,
1466
+ LookupFieldOnCalcItem__c ,
1467
+ LookupFieldOnCalcItem__r.QualifiedApiName ,
1448
1468
LookupFieldOnLookupObject__c ,
1449
1469
LookupFieldOnLookupObject__r.QualifiedApiName ,
1450
1470
RollupFieldOnLookupObject__c ,
@@ -1675,7 +1695,7 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
1675
1695
}
1676
1696
1677
1697
private static Boolean shouldRunFromTrigger () {
1678
- shouldRun = ( shouldRun != null && shouldRun ) || Trigger .isExecuting ;
1698
+ shouldRun = shouldRun || Trigger .isExecuting ;
1679
1699
// in order to accomodate CDC; we set the apexContext manually there
1680
1700
// since technically all CDC is done from an AFTER_INSERT context
1681
1701
if (Trigger .operationType != null && isCDC == false ) {
@@ -2072,7 +2092,9 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
2072
2092
@testVisible
2073
2093
private virtual class DMLHelper {
2074
2094
public virtual void doUpdate (List < SObject > recordsToUpdate ) {
2075
- update recordsToUpdate ;
2095
+ Database .DMLOptions dmlOptions = new Database .DMLOptions ();
2096
+ dmlOptions .AllowFieldTruncation = true ;
2097
+ Database .update (recordsToUpdate , dmlOptions );
2076
2098
}
2077
2099
}
2078
2100
0 commit comments