Skip to content

Commit

Permalink
Fixes #629 by properly handling text template HTML tags (when present…
Browse files Browse the repository at this point in the history
…) for the Full Recalc CMDT-driven Invocable rollup action
  • Loading branch information
jamessimone committed Oct 2, 2024
1 parent fb94e97 commit ae4a8c1
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 3 deletions.
75 changes: 75 additions & 0 deletions extra-tests/classes/RollupFlowFullRecalcDispatcherTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,81 @@ private class RollupFlowFullRecalcDispatcherTests {
System.assertEquals(5, user.Latitude);
}

@IsTest
static void supportsTextTemplateInputVariables() {
Rollup.onlyUseMockMetadata = true;
Rollup.rollupMetadata = new List<Rollup__mdt>{
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<RollupFlowFullRecalcDispatcher.FlowInput> flowInputs = getFlowInputs(Rollup.rollupMetadata);
String exampleTextTemplate = '<p><span style="background-color: rgb(255, 255, 255); font-size: 11.36px; font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);">{0}</span></p>';
flowInputs[0].rollupDeveloperNames = String.format(exampleTextTemplate, new List<String>{ 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<Rollup__mdt>{
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<String, Object>{ '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<RollupFlowFullRecalcDispatcher.FlowInput> getFlowInputs(List<Rollup__mdt> metas) {
List<RollupFlowFullRecalcDispatcher.FlowInput> flowInputs = new List<RollupFlowFullRecalcDispatcher.FlowInput>();
RollupFlowFullRecalcDispatcher.FlowInput input = new RollupFlowFullRecalcDispatcher.FlowInput();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<actionCalls>
<name>Recalc_Rollups</name>
<label>Recalc Rollups</label>
<locationX>176</locationX>
<locationY>134</locationY>
<actionName>RollupFlowFullRecalcDispatcher</actionName>
<actionType>apex</actionType>
<flowTransactionModel>CurrentTransaction</flowTransactionModel>
<inputParameters>
<name>rollupDeveloperNames</name>
<value>
<elementReference>Rollups_Comma_Separated</elementReference>
</value>
</inputParameters>
<nameSegment>RollupFlowFullRecalcDispatcher</nameSegment>
<storeOutputAutomatically>true</storeOutputAutomatically>
<versionSegment>1</versionSegment>
</actionCalls>
<apiVersion>61.0</apiVersion>
<environments>Default</environments>
<interviewLabel>Rollup Integration: Comma-Separated Full Recalc {!$Flow.CurrentDateTime}</interviewLabel>
<label>Rollup Integration: Comma-Separated Full Recalc</label>
<processMetadataValues>
<name>BuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>CanvasMode</name>
<value>
<stringValue>AUTO_LAYOUT_CANVAS</stringValue>
</value>
</processMetadataValues>
<processMetadataValues>
<name>OriginBuilderType</name>
<value>
<stringValue>LightningFlowBuilder</stringValue>
</value>
</processMetadataValues>
<processType>AutoLaunchedFlow</processType>
<start>
<locationX>50</locationX>
<locationY>0</locationY>
<connector>
<targetReference>Recalc_Rollups</targetReference>
</connector>
</start>
<status>Draft</status>
<textTemplates>
<name>Rollups_Comma_Separated</name>
<isViewedAsPlainText>false</isViewedAsPlainText>
<text
>&lt;p&gt;&lt;span style=&quot;background-color: rgb(255, 255, 255); font-size: 11.36px; font-family: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);&quot;&gt;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&lt;/span&gt;&lt;/p&gt;</text>
</textTemplates>
</Flow>
2 changes: 1 addition & 1 deletion plugins/RollupCallback/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class SubflowRollupDispatcher implements RollupSObjectUpdater.IDispatcher
decorator.FieldNames = new List<String>(record.getPopulatedFieldsAsMap().keySet());
wrappedRecords.add(decorator);
}
Flow.Interview rollupSubflow = Flow.Interview.RollupSubflow(
Flow.Interview rollupSubflow = new Flow.Interview.RollupSubflow(
new Map<String, Object>{
'records' => wrappedRecords
}
Expand Down
2 changes: 1 addition & 1 deletion rollup/core/classes/RollupFlowFullRecalcDispatcher.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> splitListOfApiNames = input.rollupDeveloperNames.split(',');
List<String> splitListOfApiNames = input.rollupDeveloperNames.stripHtmlTags().split(',');
for (String apiName : splitListOfApiNames) {
rollupDeveloperNames.add(apiName.trim());
}
Expand Down
2 changes: 1 addition & 1 deletion sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ae4a8c1

Please sign in to comment.