Skip to content

Commit

Permalink
v1.5.72 - Adding test coverage (#455)
Browse files Browse the repository at this point in the history
* Adding test coverage for DELETE-based flows properly resetting parent fields
  • Loading branch information
jamessimone authored Jun 21, 2023
1 parent 5af446f commit e06b086
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 12 deletions.
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=04t6g000008So61AAC">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008So6QAAS">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008So61AAC">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008So6QAAS">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
16 changes: 16 additions & 0 deletions extra-tests/classes/InvocableDrivenTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,20 @@ private class InvocableDrivenTests {
acc = [SELECT AnnualRevenue FROM Account];
System.assertEquals(initialNumber, acc.AnnualRevenue?.intValue(), 'Amount should have properly decremented');
}

@IsTest
static void shouldClearParentFieldOnDelete() {
RollupParent__c parent = new RollupParent__c(NumberField__c = 1, Name = 'Parent');
insert parent;

RollupChild__c child = new RollupChild__c(RollupParent__c = parent.Id, Name = 'child');
insert child;

Test.startTest();
delete child;
Test.stopTest();

parent = [SELECT NumberField__c FROM RollupParent__c WHERE Id = :parent.Id];
System.assertEquals(null, parent.NumberField__c);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="UTF-8"?>
<Flow xmlns="http://soap.sforce.com/2006/04/metadata">
<actionCalls>
<name>Perform_Rollup</name>
<label>Perform Rollup</label>
<locationX>176</locationX>
<locationY>395</locationY>
<actionName>Rollup</actionName>
<actionType>apex</actionType>
<dataTypeMappings>
<typeName>T__oldRecordsToRollup</typeName>
<typeValue>RollupChild__c</typeValue>
</dataTypeMappings>
<dataTypeMappings>
<typeName>T__recordsToRollup</typeName>
<typeValue>RollupChild__c</typeValue>
</dataTypeMappings>
<flowTransactionModel>CurrentTransaction</flowTransactionModel>
<inputParameters>
<name>lookupFieldOnCalcItem</name>
<value>
<stringValue>RollupParent__c</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>lookupFieldOnOpObject</name>
<value>
<stringValue>Id</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>recordsToRollup</name>
<value>
<elementReference>RecordsToRollup</elementReference>
</value>
</inputParameters>
<inputParameters>
<name>rollupContext</name>
<value>
<stringValue>DELETE</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>rollupFieldOnCalcItem</name>
<value>
<stringValue>Id</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>rollupFieldOnOpObject</name>
<value>
<stringValue>NumberField__c</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>rollupOperation</name>
<value>
<stringValue>COUNT</stringValue>
</value>
</inputParameters>
<inputParameters>
<name>rollupSObjectName</name>
<value>
<stringValue>RollupParent__c</stringValue>
</value>
</inputParameters>
<nameSegment>Rollup</nameSegment>
<storeOutputAutomatically>true</storeOutputAutomatically>
<versionSegment>1</versionSegment>
</actionCalls>
<apiVersion>58.0</apiVersion>
<assignments>
<name>Add_deleted_record_to_collection</name>
<label>Add deleted record to collection</label>
<locationX>176</locationX>
<locationY>287</locationY>
<assignmentItems>
<assignToReference>RecordsToRollup</assignToReference>
<operator>Add</operator>
<value>
<elementReference>$Record</elementReference>
</value>
</assignmentItems>
<connector>
<targetReference>Perform_Rollup</targetReference>
</connector>
</assignments>
<environments>Default</environments>
<interviewLabel>Rollup Integration - REFRESH on delete clears value {!$Flow.CurrentDateTime}</interviewLabel>
<label>Rollup Integration - refresh on delete clears value</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>Add_deleted_record_to_collection</targetReference>
</connector>
<object>RollupChild__c</object>
<recordTriggerType>Delete</recordTriggerType>
<triggerType>RecordBeforeDelete</triggerType>
</start>
<status>Active</status>
<variables>
<name>RecordsToRollup</name>
<dataType>SObject</dataType>
<isCollection>true</isCollection>
<isInput>true</isInput>
<isOutput>false</isOutput>
<objectType>RollupChild__c</objectType>
</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.5.71",
"version": "1.5.72",
"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
6 changes: 3 additions & 3 deletions rollup-namespaced/sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"default": true,
"package": "apex-rollup-namespaced",
"path": "rollup-namespaced/source/rollup",
"versionName": "Summer 23 updates",
"versionNumber": "1.0.44.0",
"versionName": "Test coverage for DELETE-based flows resetting values",
"versionNumber": "1.0.45.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 All @@ -26,4 +26,4 @@
"apex-rollup-namespaced@1.0.43-0": "04t6g000008SnrcAAC",
"apex-rollup-namespaced@1.0.44-0": "04t6g000008So66AAC"
}
}
}
6 changes: 4 additions & 2 deletions rollup/core/classes/Rollup.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2051,18 +2051,20 @@ global without sharing virtual class Rollup implements RollupLogger.ToStringObje

if (queryWrapper?.hasQuery == true) {
metas.remove(index);
String query = queryWrapper.getQuery();
RollupMetadata wrappedMeta = getWrappedMeta(
calcItemSObjectType,
typeToWrappedMeta,
meta,
queryWrapper.getQuery() + (String.isNotBlank(meta.CalcItemWhereClause__c) ? ' AND ' + meta.CalcItemWhereClause__c : '')
query + (String.isNotBlank(meta.CalcItemWhereClause__c) ? ' AND ' + meta.CalcItemWhereClause__c : '')
);
if (rollups.containsKey(calcItemSObjectType)) {
rollups.get(calcItemSObjectType).clear();
}
wrappedMeta.recordIds.addAll(queryWrapper.recordIds);
if (wrappedMeta.recordIds.isEmpty() == false) {
wrappedMeta.possibleWhereClauses.add(queryWrapper.getQuery());
wrappedMeta.possibleWhereClauses.add(query);
wrappedMeta.whereClause = query;
}
wrappedMeta.parentRecordsToReset.addAll(queryWrapper.parentRecordsToReset);
appendQueryCount(wrappedMeta, meta, wrappedMeta.whereClause, calcItemSObjectType);
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.5.71';
private static final String CURRENT_VERSION_NUMBER = 'v1.5.72';
private static final LoggingLevel FALLBACK_LOGGING_LEVEL = LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
7 changes: 4 additions & 3 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"default": true,
"package": "apex-rollup",
"path": "rollup",
"versionName": "Summer 23 updates",
"versionNumber": "1.5.71.0",
"versionName": "Test coverage for DELETE-based flows resetting values",
"versionNumber": "1.5.72.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 @@ -104,6 +104,7 @@
"apex-rollup@1.5.68-0": "04t6g000008SnlYAAS",
"apex-rollup@1.5.69-0": "04t6g000008SnlnAAC",
"apex-rollup@1.5.70-0": "04t6g000008SnrXAAS",
"apex-rollup@1.5.71-0": "04t6g000008So61AAC"
"apex-rollup@1.5.71-0": "04t6g000008So61AAC",
"apex-rollup@1.5.72-0": "04t6g000008So6QAAS"
}
}

0 comments on commit e06b086

Please sign in to comment.