Skip to content

Commit

Permalink
Fixes #556 by properly detecting when subsequent DML statements enque…
Browse files Browse the repository at this point in the history
…ued by Flow triggers should react to deletes
  • Loading branch information
jamessimone committed Feb 7, 2024
1 parent 7020358 commit d53dfb6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 16 deletions.
31 changes: 31 additions & 0 deletions extra-tests/classes/RollupFlowTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1033,4 +1033,35 @@ private class RollupFlowTests {
System.assertNotEquals('No records to rollup, returning early', flowOutputs[0].message);
System.assertEquals(null, acc.AnnualRevenue);
}

@IsTest
static void worksWithMultipleDmlWithDeletes() {
Account acc = [SELECT Id FROM Account];
acc.AnnualRevenue = 1;
RollupAsyncProcessor.stubParentRecords = new List<SObject>{ acc };

List<ContactPointAddress> cpas = new List<ContactPointAddress>{
new ContactPointAddress(PreferenceRank = 1, ParentId = acc.Id, Name = 'Non-match 1'),
new ContactPointAddress(PreferenceRank = 2, ParentId = acc.Id, Name = 'Match to be deleted')
};
insert cpas;

ContactPointAddress toDelete = cpas.remove(1);
List<ContactPointAddress> deletedCpas = new List<ContactPointAddress>{ toDelete };

List<Rollup.FlowInput> flowInputs = RollupTestUtils.prepareFlowTest(deletedCpas, 'UPDATE', 'COUNT');
flowInputs[0].oldRecordsToRollup = new List<ContactPointAddress>(deletedCpas);
flowInputs[0].isFullRecordSet = true;
flowInputs[0].calcItemWhereClause = 'PreferenceRank = 2';
flowInputs.addAll(RollupTestUtils.prepareFlowTest(deletedCpas, 'DELETE', 'COUNT'));
flowInputs[1].calcItemWhereClause = 'PreferenceRank = 2';
flowInputs[1].isFullRecordSet = true;

Test.startTest();
Rollup.performRollup(flowInputs);
Test.stopTest();

Account updatedAcc = [SELECT Id, AnnualRevenue FROM Account WHERE Id = :acc.Id];
System.assertEquals(null, updatedAcc.AnnualRevenue);
}
}
10 changes: 0 additions & 10 deletions rollup-namespaced/sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@
"sourceApiVersion": "58.0",
"packageAliases": {
"apex-rollup-namespaced": "0Ho6g000000PBMjCAO",
"apex-rollup-namespaced@1.0.51-0": "04t6g000008C71cAAC",
"apex-rollup-namespaced@1.0.52-0": "04t6g000008C72GAAS",
"apex-rollup-namespaced@1.0.53-0": "04t6g000008C739AAC",
"apex-rollup-namespaced@1.1.0-0": "04t6g000008C7AVAA0",
"apex-rollup-namespaced@1.1.1-0": "04t6g000008OZwdAAG",
"apex-rollup-namespaced@1.1.2-0": "04t6g000008Oa7YAAS",
"apex-rollup-namespaced@1.1.3": "04t6g000008Oa8lAAC",
"apex-rollup-namespaced@1.1.4": "04t6g000008Oa9ZAAS",
"apex-rollup-namespaced@1.1.5": "04t6g000008OaAcAAK",
"apex-rollup-namespaced@1.1.6": "04t6g000008OaFnAAK",
"apex-rollup-namespaced@1.1.7": "04t6g000008OaJQAA0",
"apex-rollup-namespaced@1.1.8": "04t6g000008OaJpAAK",
"apex-rollup-namespaced@1.1.9": "04t6g000008OaLHAA0",
Expand Down
2 changes: 1 addition & 1 deletion rollup/core/classes/RollupAsyncProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
// calling clear in a loop here might look interesting - and it would be a massive problem if not for the
// bag only responding to the very first clear() invocation. everything after that is a no-op (so, any rollup with more
// than one rollup operation going at a time)
if (rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE) {
if (rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE || rollup.op.name().contains('DELETE')) {
bag.clear();
}
}
Expand Down
2 changes: 1 addition & 1 deletion rollup/core/classes/RollupLogger.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
global without sharing virtual class RollupLogger implements ILogger {
@TestVisible
// this gets updated via the pipeline as the version number gets incremented
private static final String CURRENT_VERSION_NUMBER = 'v1.6.11';
private static final String CURRENT_VERSION_NUMBER = 'v1.6.12-beta';
private static final LoggingLevel FALLBACK_LOGGING_LEVEL = LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
6 changes: 2 additions & 4 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"package": "apex-rollup",
"path": "rollup",
"scopeProfiles": true,
"versionName": "Continuation from v1.6.5 with big CPU time improvements made to Flow-based rollups, particularly for the update record code path",
"versionNumber": "1.6.11.0",
"versionName": "Flow bugfix for flows triggered via Apex that both update AND delete records",
"versionNumber": "1.6.12.0",
"versionDescription": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"releaseNotesUrl": "https://github.com/jamessimone/apex-rollup/releases/latest",
"unpackagedMetadata": {
Expand Down Expand Up @@ -100,8 +100,6 @@
"Apex Rollup - Rollup Callback@0.0.3-0": "04t6g000008Sis0AAC",
"Nebula Logger - Core@4.8.0-NEXT-ignore-origin-method": "04t5Y0000015lslQAA",
"apex-rollup": "0Ho6g000000TNcOCAW",
"apex-rollup@1.6.8": "04t6g000008OaJLAA0",
"apex-rollup@1.6.9": "04t6g000008OaJkAAK",
"apex-rollup@1.6.10": "04t6g000008OaLCAA0",
"apex-rollup@1.6.11": "04t6g000008OaO6AAK"
}
Expand Down

0 comments on commit d53dfb6

Please sign in to comment.