Skip to content

Commit

Permalink
Fixes #619 by more carefully handling parentRecordIdForEmptyChildrenC…
Browse files Browse the repository at this point in the history
…ollections variable
  • Loading branch information
jamessimone committed Sep 5, 2024
1 parent af39cbd commit f400653
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ sfge-*.log.gz
.DS_Store
.config
.vscode
config/data/act-pr-event.json
config/data/act-pr-event.json
.sflogsub
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ As well, don't miss [the Wiki](../../wiki), which includes even more info for co

## Deployment & Setup

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObeQAAS">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Obg7AAC">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObeQAAS">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008Obg7AAC">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
21 changes: 19 additions & 2 deletions extra-tests/classes/InvocableDrivenTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ private class InvocableDrivenTests {
@TestSetup
static void setup() {
upsert new RollupSettings__c(IsEnabled__c = true);
Account acc = new Account(Name = InvocableDrivenTests.class.getName());
insert acc;
insert new Account(Name = InvocableDrivenTests.class.getName());
}

@IsTest
Expand Down Expand Up @@ -182,4 +181,22 @@ private class InvocableDrivenTests {
parent = [SELECT AnnualRevenue FROM Account WHERE Id = :parent.Id];
System.assertEquals(null, parent.AnnualRevenue);
}

@IsTest
static void refreshWorksWithEmptyCollectionsWhenParentIdIsProvided() {
Account acc = [SELECT Id FROM Account];
ContactPointAddress child = new ContactPointAddress(Name = 'RollupIntegrationRefresh', PreferenceRank = 99, ParentId = acc.Id);
insert child;

Flow.Interview flowInterview = new Flow.Interview.Rollup_Integration_Refresh_With_Empty_Collections(
new Map<String, Object>{ 'parentRecordIdForEmptyChildrenCollections' => acc.Id }
);

Test.startTest();
flowInterview.start();
Test.stopTest();

acc = [SELECT AnnualRevenue FROM Account WHERE Id = :acc.Id];
System.assertEquals(child.PreferenceRank, acc.AnnualRevenue);
}
}
1 change: 1 addition & 0 deletions extra-tests/classes/RollupTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,7 @@ private class RollupTests {
RollupTestUtils.DMLMock mock = RollupTestUtils.loadMock(new List<ContactPointAddress>{ somethingElseName });
Rollup.oldRecordsMap = new Map<Id, SObject>{ somethingElseName.Id => somethingElseName };
Rollup.apexContext = TriggerOperation.BEFORE_DELETE;
Rollup.onlyUseMockMetadata = true;
Rollup.rollupMetadata = new List<Rollup__mdt>{
new Rollup__mdt(
CalcItem__c = 'ContactPointAddress',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Rollup Integration: REFRESH</label>
<protected>false</protected>
<values>
<field>CalcItemText__c</field>
<value xsi:type="xsd:string">ContactPointAddress</value>
</values>
<values>
<field>CalcItemWhereClause__c</field>
<value xsi:type="xsd:string">Name = &apos;RollupIntegrationRefresh&apos;</value>
</values>
<values>
<field>CalcItem__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>ChangedFieldsOnCalcItem__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>ConcatDelimiter__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>CurrencyFieldMapping__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>Description__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>FullRecalculationDefaultNumberValue__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>FullRecalculationDefaultStringValue__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>GrandparentRelationshipFieldPath__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>GroupByFields__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>GroupByRowEndDelimiter__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>GroupByRowStartDelimiter__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>IsDistinct__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>IsFullRecordSet__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>IsRollupStartedFromParent__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>IsTableFormatted__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>LimitAmount__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>LookupFieldOnCalcItemText__c</field>
<value xsi:type="xsd:string">ParentId</value>
</values>
<values>
<field>LookupFieldOnCalcItem__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>LookupFieldOnLookupObjectText__c</field>
<value xsi:type="xsd:string">Id</value>
</values>
<values>
<field>LookupFieldOnLookupObject__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>LookupObjectText__c</field>
<value xsi:type="xsd:string">Account</value>
</values>
<values>
<field>LookupObject__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>OneToManyGrandparentFields__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>OrderByFirstLast__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>RollupControl__c</field>
<value xsi:type="xsd:string">Org_Defaults</value>
</values>
<values>
<field>RollupFieldOnCalcItemText__c</field>
<value xsi:type="xsd:string">PreferenceRank</value>
</values>
<values>
<field>RollupFieldOnCalcItem__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>RollupFieldOnLookupObjectText__c</field>
<value xsi:type="xsd:string">AnnualRevenue</value>
</values>
<values>
<field>RollupFieldOnLookupObject__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>RollupGrouping__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>RollupOperation__c</field>
<value xsi:type="xsd:string">SUM</value>
</values>
<values>
<field>RollupToUltimateParent__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>SharingMode__c</field>
<value xsi:nil="true" />
</values>
<values>
<field>ShouldRunWithoutCustomSettingEnabled__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>SplitConcatDelimiterOnCalcItem__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>UltimateParentLookup__c</field>
<value xsi:nil="true" />
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<actionCalls>
<name>Rollup_ContactPointConsent_Record</name>
<label>Rollup ContactPointConsent Record</label>
<locationX>176</locationX>
<locationY>134</locationY>
<actionName>RollupFlowBulkProcessor</actionName>
<actionType>apex</actionType>
<dataTypeMappings>
<typeName>T__oldRecordsToRollup</typeName>
<typeValue>ContactPointAddress</typeValue>
</dataTypeMappings>
<dataTypeMappings>
<typeName>T__recordsToRollup</typeName>
<typeValue>ContactPointAddress</typeValue>
</dataTypeMappings>
<flowTransactionModel>CurrentTransaction</flowTransactionModel>
<inputParameters>
<name>calcItemTypeWhenRollupStartedFromParent</name>
<value>
<stringValue>ContactPointAddress</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>deferProcessing</name>
<value>
<booleanValue>false</booleanValue>
</value>
</inputParameters>
<inputParameters>
<name>parentRecordIdForEmptyChildrenCollections</name>
<value>
<elementReference>parentRecordIdForEmptyChildrenCollections</elementReference>
</value>
</inputParameters>
<inputParameters>
<name>rollupContext</name>
<value>
<stringValue>REFRESH</stringValue>
</value>
</inputParameters>
<nameSegment>RollupFlowBulkProcessor</nameSegment>
<storeOutputAutomatically>true</storeOutputAutomatically>
<versionSegment>1</versionSegment>
</actionCalls>
<apiVersion>61.0</apiVersion>
<environments>Default</environments>
<interviewLabel>Rollup Integration - Refresh With Empty Collections {!$Flow.CurrentDateTime}</interviewLabel>
<label>Rollup Integration - Refresh With Empty Collections</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>Rollup_ContactPointConsent_Record</targetReference>
</connector>
</start>
<status>Obsolete</status>
<variables>
<name>parentRecordIdForEmptyChildrenCollections</name>
<dataType>String</dataType>
<isCollection>false</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
</variables>
</Flow>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apex-rollup",
"version": "1.6.33",
"version": "1.6.34",
"description": "Fast, configurable, elastically scaling custom rollup solution. Apex Invocable action, one-liner Apex trigger/CMDT-driven logic, and scheduled Apex-ready.",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions plugins/ExtraCodeCoverage/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Extra Code Coverage

<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObVmAAK">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObgCAAS">
<img alt="Deploy to Salesforce"
src="../../media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObVmAAK">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008ObgCAAS">
<img alt="Deploy to Salesforce Sandbox"
src="../../media/deploy-package-to-sandbox.png">
</a>
Expand Down
2 changes: 1 addition & 1 deletion rollup/core/classes/Rollup.cls
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ global without sharing virtual class Rollup implements RollupLogger.ToStringObje
public RollupGrouping__mdt rollupGrouping;

public Boolean shouldOverrideNoOp() {
return this.parentRecordIdForEmptyChildrenCollections != null && calcItemTypeWhenRollupStartedFromParent != null;
return this.parentRecordIdForEmptyChildrenCollections != null && this.calcItemTypeWhenRollupStartedFromParent != null;
}
}

Expand Down
14 changes: 5 additions & 9 deletions rollup/core/classes/RollupFlowBulkProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,23 @@ global without sharing class RollupFlowBulkProcessor {
List<Rollup.FlowInput> validInputs = new List<Rollup.FlowInput>();
for (FlowInput flowInput : flowInputs) {
Rollup.FlowOutput output = new Rollup.FlowOutput();
if (flowInput.recordsToRollup?.isEmpty() != false) {
if (flowInput.recordsToRollup?.isEmpty() != false && flowInput.parentRecordIdForEmptyChildrenCollections == null) {
output.message = 'No records';
outputs.add(output);
} else {
List<Rollup__mdt> rollupMetadata = Rollup.getMetadataFromCache(Rollup__mdt.SObjectType);
// for some reason, lists passed from Flow to Apex report their SObjectType as null. womp.
Schema.SObjectType sObjectType = flowInput.recordsToRollup?.get(0).getSObjectType();
String childName = sObjectType?.getDescribe(SObjectDescribeOptions.DEFERRED).getName();
for (Rollup__mdt meta : rollupMetadata) {
if (
meta.IsRollupStartedFromParent__c ||
sObjectType != null && String.isNotBlank(meta.GrandparentRelationshipFieldPath__c) && Rollup.getPartOfGrandparentChain(meta, sObjectType) != null
) {
flowInput.calcItemTypeWhenRollupStartedFromParent = flowInput.calcItemTypeWhenRollupStartedFromParent != null
? flowInput.calcItemTypeWhenRollupStartedFromParent
: meta.CalcItem__c;
flowInput.calcItemTypeWhenRollupStartedFromParent = flowInput.calcItemTypeWhenRollupStartedFromParent ?? meta.CalcItem__c;
}
if (
flowInput.recordsToRollup == null ||
meta.CalcItem__c == sObjectType?.getDescribe(SObjectDescribeOptions.DEFERRED).getName() ||
flowInput.calcItemTypeWhenRollupStartedFromParent == meta.CalcItem__c
) {
Boolean isMatchingParentSide = flowInput.calcItemTypeWhenRollupStartedFromParent == meta.CalcItem__c;
if ((flowInput.recordsToRollup?.isEmpty() != false && isMatchingParentSide) || meta.CalcItem__c == childName || isMatchingParentSide) {
Rollup.FlowInput input = new Rollup.FlowInput();
validInputs.add(input);
// pertinent fields from CMDT (can be overridden by optional flow properties)
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.33';
private static final String CURRENT_VERSION_NUMBER = 'v1.6.34-beta';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
Loading

0 comments on commit f400653

Please sign in to comment.