Skip to content

Commit

Permalink
Further fixes for #95 after getting feedback from Katherine on beta p…
Browse files Browse the repository at this point in the history
…ackage version
  • Loading branch information
jamessimone committed May 8, 2021
1 parent 00fc33f commit eb35418
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 173 deletions.
15 changes: 11 additions & 4 deletions rollup/core/classes/Rollup.cls
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
private static Integer stackDepth = 0;
private static final String CONTROL_ORG_DEFAULTS = 'Org_Defaults';
private static final RollupSettings__c SETTINGS = RollupSettings__c.getInstance();
private static final Set<String> ALWAYS_FULL_RECALC_OPS = new Set<String>{ Op.FIRST.name(), Op.LAST.name(), Op.AVERAGE.name() };

private final List<SObject> calcItems;
private final Map<Id, SObject> oldCalcItems;
Expand Down Expand Up @@ -1954,6 +1955,7 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
Rollup batchRollup = new RollupAsyncProcessor(rollupInvokePoint);
DescribeSObjectResult describeForSObject = sObjectType.getDescribe();
Map<String, SObjectField> fieldNameToField = describeForSObject.fields.getMap();

for (Rollup__mdt rollupMetadata : rollupOperations) {
Op rollupOp = opNameToOp.get(rollupMetadata.RollupOperation__c.toUpperCase());
SObjectField rollupFieldOnCalcItem = getSObjectFieldByName(describeForSObject, rollupMetadata.RollupFieldOnCalcItem__c);
Expand All @@ -1972,6 +1974,10 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
rollupMetadata.LookupFieldOnLookupObject__c = lookupFieldOnOpObject.getDescribe().getName();
rollupMetadata.RollupFieldOnLookupObject__c = rollupFieldOnOpObject.getDescribe().getName();

if (rollupMetadata.IsFullRecordSet__c == false && ALWAYS_FULL_RECALC_OPS.contains(getBareOperationName(rollupMetadata.RollupOperation__c))) {
rollupMetadata.IsFullRecordSet__c = true;
}

RollupControl__mdt localControl;
if (rollupMetadata.RollupControl__c != null) {
// for CMDT-driven rollups, the rollup record is always tied to a RollupControl__mdt record
Expand Down Expand Up @@ -2176,7 +2182,6 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec

private static FilterResults filter(List<SObject> calcItems, Map<Id, SObject> oldCalcItems, Evaluator eval, Rollup__mdt metadata, SObjectType calcItemType) {
FilterResults results = new FilterResults();
Set<String> alwaysFullRecalcOps = new Set<String>{ 'FIRST', 'LAST', 'AVERAGE' };
List<SObject> matchingItems = calcItems == null ? new List<SObject>() : calcItems.clone();
results.matchingItems = matchingItems;
if (matchingItems.isEmpty()) {
Expand All @@ -2198,8 +2203,6 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
// have to do this EXTRA explicit check
} else if (metadata?.IsFullRecordSet__c == true) {
matchingItems.add(item);
} else if (alwaysFullRecalcOps.contains(metadata?.RollupOperation__c)) {
matchingItems.add(item);
}
}
return results;
Expand Down Expand Up @@ -2276,6 +2279,10 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
}
}

private static String getBareOperationName(String fullOpName) {
return fullOpName.contains('_') ? fullOpName.substringAfter('_') : fullOpName;
}

/** End static section, begin protected + private instance methods */

protected Rollup getDelegatedRollup(
Expand Down Expand Up @@ -2637,7 +2644,7 @@ global without sharing virtual class Rollup implements Database.Batchable<SObjec
continue;
}

String currentOp = rollup.op.name().contains('_') ? rollup.op.name().substringAfter('_') : rollup.op.name();
String currentOp = getBareOperationName(rollup.op.name());
String deleteOpName = 'DELETE_' + currentOp;
Op deleteOp = opNameToOp.get(deleteOpName);
Rollup oldLookupsRollup = new Rollup(rollup, deleteOp, reparentedCalcItems);
Expand Down
Loading

0 comments on commit eb35418

Please sign in to comment.