From ae4a8c163f5c118377f8ae2788e4a7db1caa9d98 Mon Sep 17 00:00:00 2001 From: James Simone <16430727+jamessimone@users.noreply.github.com> Date: Wed, 2 Oct 2024 10:08:20 -0400 Subject: [PATCH] Fixes #629 by properly handling text template HTML tags (when present) for the Full Recalc CMDT-driven Invocable rollup action --- .../RollupFlowFullRecalcDispatcherTests.cls | 75 +++++++++++++++++++ ..._Comma_Separated_Full_Recalc.flow-meta.xml | 58 ++++++++++++++ plugins/RollupCallback/README.md | 2 +- .../RollupFlowFullRecalcDispatcher.cls | 2 +- sfdx-project.json | 2 +- 5 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 extra-tests/flows/Rollup_Integration_Comma_Separated_Full_Recalc.flow-meta.xml diff --git a/extra-tests/classes/RollupFlowFullRecalcDispatcherTests.cls b/extra-tests/classes/RollupFlowFullRecalcDispatcherTests.cls index a84bba15..5dea8360 100644 --- a/extra-tests/classes/RollupFlowFullRecalcDispatcherTests.cls +++ b/extra-tests/classes/RollupFlowFullRecalcDispatcherTests.cls @@ -120,6 +120,81 @@ private class RollupFlowFullRecalcDispatcherTests { System.assertEquals(5, user.Latitude); } + @IsTest + static void supportsTextTemplateInputVariables() { + Rollup.onlyUseMockMetadata = true; + Rollup.rollupMetadata = new List{ + new Rollup__mdt( + DeveloperName = 'cmdt1', + CalcItem__c = 'ContactPointAddress', + RollupFieldOnCalcItem__c = 'PreferenceRank', + LookupFieldOnCalcItem__c = 'ParentId', + LookupObject__c = 'Account', + LookupFieldOnLookupObject__c = 'Id', + RollupFieldOnLookupObject__c = 'AnnualRevenue', + RollupOperation__c = 'SUM', + CalcItemWhereClause__c = 'PreferenceRank = 1' + ), + new Rollup__mdt( + DeveloperName = 'cmdt2', + CalcItem__c = 'ContactPointAddress', + RollupFieldOnCalcItem__c = 'PreferenceRank', + LookupFieldOnCalcItem__c = 'ParentId', + LookupObject__c = 'Account', + LookupFieldOnLookupObject__c = 'Id', + RollupFieldOnLookupObject__c = 'NumberOfEmployees', + RollupOperation__c = 'COUNT' + ) + }; + List flowInputs = getFlowInputs(Rollup.rollupMetadata); + String exampleTextTemplate = '

{0}

'; + flowInputs[0].rollupDeveloperNames = String.format(exampleTextTemplate, new List{ flowInputs[0].rollupDeveloperNames }); + + Test.startTest(); + RollupFlowFullRecalcDispatcher.performFullRecalcRollups(flowInputs); + Test.stopTest(); + + Account acc = [SELECT AnnualRevenue, NumberOfEmployees FROM Account]; + System.assertEquals(6, acc.AnnualRevenue); + System.assertEquals(6, acc.NumberOfEmployees); + } + + @IsTest + static void integrationSupportsTextTemplateVariables() { + Rollup.onlyUseMockMetadata = true; + Rollup.rollupMetadata = new List{ + new Rollup__mdt( + DeveloperName = 'cmdt1', + CalcItem__c = 'ContactPointAddress', + RollupFieldOnCalcItem__c = 'PreferenceRank', + LookupFieldOnCalcItem__c = 'ParentId', + LookupObject__c = 'Account', + LookupFieldOnLookupObject__c = 'Id', + RollupFieldOnLookupObject__c = 'AnnualRevenue', + RollupOperation__c = 'SUM', + CalcItemWhereClause__c = 'PreferenceRank = 1' + ), + new Rollup__mdt( + DeveloperName = 'cmdt2', + CalcItem__c = 'ContactPointAddress', + RollupFieldOnCalcItem__c = 'PreferenceRank', + LookupFieldOnCalcItem__c = 'ParentId', + LookupObject__c = 'Account', + LookupFieldOnLookupObject__c = 'Id', + RollupFieldOnLookupObject__c = 'NumberOfEmployees', + RollupOperation__c = 'COUNT' + ) + }; + + Test.startTest(); + new Flow.Interview.Rollup_Integration_Comma_Separated_Full_Recalc(new Map{ 'rollupNames' => 'cmdt1, cmdt2' }).start(); + Test.stopTest(); + + Account acc = [SELECT AnnualRevenue, NumberOfEmployees FROM Account]; + System.assertEquals(6, acc.AnnualRevenue); + System.assertEquals(6, acc.NumberOfEmployees); + } + private static List getFlowInputs(List metas) { List flowInputs = new List(); RollupFlowFullRecalcDispatcher.FlowInput input = new RollupFlowFullRecalcDispatcher.FlowInput(); diff --git a/extra-tests/flows/Rollup_Integration_Comma_Separated_Full_Recalc.flow-meta.xml b/extra-tests/flows/Rollup_Integration_Comma_Separated_Full_Recalc.flow-meta.xml new file mode 100644 index 00000000..7dd5f36e --- /dev/null +++ b/extra-tests/flows/Rollup_Integration_Comma_Separated_Full_Recalc.flow-meta.xml @@ -0,0 +1,58 @@ + + + + Recalc_Rollups + + 176 + 134 + RollupFlowFullRecalcDispatcher + apex + CurrentTransaction + + rollupDeveloperNames + + Rollups_Comma_Separated + + + RollupFlowFullRecalcDispatcher + true + 1 + + 61.0 + Default + Rollup Integration: Comma-Separated Full Recalc {!$Flow.CurrentDateTime} + + + BuilderType + + LightningFlowBuilder + + + + CanvasMode + + AUTO_LAYOUT_CANVAS + + + + OriginBuilderType + + LightningFlowBuilder + + + AutoLaunchedFlow + + 50 + 0 + + Recalc_Rollups + + + Draft + + Rollups_Comma_Separated + false + <p><span style="background-color: rgb(255, 255, 255); font-size: 11.36px; font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">All_Item_D,Paid_and_Item_D,Unpaid_Items_Like_A,Child_to_Parent_D_Unpaid,Child_to_Parent_Not_DAG_Unpaid,Child_to_Parent_Unpaid,Child_to_C_Paid_Amount,Child_to_B_Paid_Amount</span></p> + + diff --git a/plugins/RollupCallback/README.md b/plugins/RollupCallback/README.md index 7192ab89..cceb6fa8 100644 --- a/plugins/RollupCallback/README.md +++ b/plugins/RollupCallback/README.md @@ -109,7 +109,7 @@ public class SubflowRollupDispatcher implements RollupSObjectUpdater.IDispatcher decorator.FieldNames = new List(record.getPopulatedFieldsAsMap().keySet()); wrappedRecords.add(decorator); } - Flow.Interview rollupSubflow = Flow.Interview.RollupSubflow( + Flow.Interview rollupSubflow = new Flow.Interview.RollupSubflow( new Map{ 'records' => wrappedRecords } diff --git a/rollup/core/classes/RollupFlowFullRecalcDispatcher.cls b/rollup/core/classes/RollupFlowFullRecalcDispatcher.cls index a59326bf..0fb35935 100644 --- a/rollup/core/classes/RollupFlowFullRecalcDispatcher.cls +++ b/rollup/core/classes/RollupFlowFullRecalcDispatcher.cls @@ -15,7 +15,7 @@ global without sharing class RollupFlowFullRecalcDispatcher { if (String.isBlank(input.rollupDeveloperNames)) { throw new IllegalArgumentException('Comma-separated list of Rollup__mdt DeveloperName(s) was not provided'); } - List splitListOfApiNames = input.rollupDeveloperNames.split(','); + List splitListOfApiNames = input.rollupDeveloperNames.stripHtmlTags().split(','); for (String apiName : splitListOfApiNames) { rollupDeveloperNames.add(apiName.trim()); } diff --git a/sfdx-project.json b/sfdx-project.json index 5764331d..ed57eae5 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -5,7 +5,7 @@ "package": "apex-rollup", "path": "rollup", "scopeProfiles": true, - "versionName": "Fixes Rollup Order By sorting to always be deterministic", + "versionName": "Fixes Rollup Order By sorting to always be deterministic, allows text templates in Full Recalc CMDT-driven Invocable invocable", "versionNumber": "1.6.35.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",