Skip to content

Commit

Permalink
v1.6.23 - Configurable Errors Thrown On Save (#584)
Browse files Browse the repository at this point in the history
* Fixes an issue long-discussed in #523 that allows subscribers to throw errors on save with Apex Rollup instead of logging a WARN message
  • Loading branch information
jamessimone committed Apr 23, 2024
1 parent b7cafd8 commit d8ff7fa
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 21 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=04t6g000008OavAAAS">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OawIAAS">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavAAAS">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OawIAAS">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
18 changes: 17 additions & 1 deletion extra-tests/classes/RollupSObjectUpdaterTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class RollupSObjectUpdaterTests {
RollupPlugin.parameterMock = new RollupPluginParameter__mdt(Value__c = DispatcherMock.class.getName());
RollupSObjectUpdater updater = new RollupSObjectUpdater();

updater.doUpdate(new List<SObjecT>{ new Account() });
updater.doUpdate(new List<SObject>{ new Account() });

System.assertEquals(true, dispatcherMockWasCalled);
}
Expand Down Expand Up @@ -141,6 +141,22 @@ public class RollupSObjectUpdaterTests {
System.assertNotEquals(initial, RollupSettings__c.getInstance());
}

@IsTest
static void shouldThrowWhenControlValueEnabledForFailedSaves() {
RollupSObjectUpdater updater = new RollupSObjectUpdater();
updater.addRollupControl(new RollupControl__mdt(ShouldThrowOnSaveErrors__c = true));

String message = '';
try {
updater.doUpdate(new List<SObject>{ new Account() });
Assert.fail('Error should be thrown for account without Id');
} catch (System.DmlException ex) {
message = ex.getMessage();
}

Assert.areEqual('Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []', message);
}

public class MockUpdater implements RollupSObjectUpdater.IUpdater {
public void performUpdate(List<SObject> recordsToUpdate, Database.DMLOptions options) {
mockUpdatedRecords = recordsToUpdate;
Expand Down
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.22",
"version": "1.6.23",
"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 rollup-namespaced/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ For more info, see the base `README`.

## Deployment & Setup

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

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OavFAAS">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OawNAAS">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
2 changes: 1 addition & 1 deletion rollup-namespaced/sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"apex-rollup-namespaced@1.1.13": "04t6g000008OaYwAAK",
"apex-rollup-namespaced@1.1.14": "04t6g000008OaZBAA0",
"apex-rollup-namespaced@1.1.16": "04t6g000008OaZaAAK",
"apex-rollup-namespaced@1.1.17": "04t6g000008OavFAAS"
"apex-rollup-namespaced@1.1.17": "04t6g000008OawNAAS"
}
}
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.22';
private static final String CURRENT_VERSION_NUMBER = 'v1.6.23';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
3 changes: 1 addition & 2 deletions rollup/core/classes/RollupSObjectUpdater.cls
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ global without sharing virtual class RollupSObjectUpdater {
recordsToUpdate.sort(SORTER);
Database.DMLOptions dmlOptions = new Database.DMLOptions();
dmlOptions.AllowFieldTruncation = true;
// TODO - possibly add configuration for this option as per #523
dmlOptions.OptAllOrNone = false;
dmlOptions.OptAllOrNone = this.rollupControl.ShouldThrowOnSaveErrors__c;
if (this.rollupControl.ShouldDuplicateRulesBeIgnored__c != false) {
dmlOptions.DuplicateRuleHeader.AllowSave = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
<field>MaxNumberOfQueries__c</field>
<value xsi:type="xsd:double">50.0</value>
</values>
<values>
<field>MaxQueryRows__c</field>
<value xsi:type="xsd:double">25000.0</value>
</values>
<values>
<field>MaxParentRowsUpdatedAtOnce__c</field>
<value xsi:type="xsd:double">5000.0</value>
</values>
<values>
<field>MaxQueryRows__c</field>
<value xsi:type="xsd:double">25000.0</value>
</values>
<values>
<field>MaxRollupRetries__c</field>
<value xsi:type="xsd:double">10.0</value>
Expand Down Expand Up @@ -70,6 +70,10 @@
<field>ShouldSkipResettingParentFields__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>ShouldThrowOnSaveErrors__c</field>
<value xsi:type="xsd:boolean">false</value>
</values>
<values>
<field>TriggerOrInvocableName__c</field>
<value xsi:nil="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<behavior>Edit</behavior>
<field>IsDevEdOrTrialOrg__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>IsMergeReparentingEnabled__c</field>
</layoutItems>
</layoutColumns>
<layoutColumns>
<layoutItems>
Expand All @@ -36,6 +40,10 @@
<behavior>Edit</behavior>
<field>ShouldDuplicateRulesBeIgnored__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ShouldThrowOnSaveErrors__c</field>
</layoutItems>
<layoutItems>
<behavior>Required</behavior>
<field>ShouldRunAs__c</field>
Expand All @@ -44,10 +52,6 @@
<behavior>Edit</behavior>
<field>ShouldRunSingleRecordsSynchronously__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>IsMergeReparentingEnabled__c</field>
</layoutItems>
</layoutColumns>
<style>TwoColumnsLeftToRight</style>
</layoutSections>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>ShouldThrowOnSaveErrors__c</fullName>
<defaultValue>false</defaultValue>
<description
>By default, errors when saving parent records are logged but execution does not halt. Set this to true to throw errors for validations rules and other exceptions.</description>
<externalId>false</externalId>
<fieldManageability>SubscriberControlled</fieldManageability>
<inlineHelpText
>By default, errors when saving parent records are logged but execution does not halt. Set this to true to throw errors for validations rules and other exceptions.</inlineHelpText>
<label>Should Throw On Save Errors</label>
<type>Checkbox</type>
</CustomField>
7 changes: 4 additions & 3 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": "Fixes grandparent rollup logic for deletes with COUNT_DISTINCT",
"versionNumber": "1.6.22.0",
"versionName": "Adds support for exceptions to be thrown when parent-level saves errors occur",
"versionNumber": "1.6.23.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 @@ -105,6 +105,7 @@
"apex-rollup@1.6.19": "04t6g000008Oal4AAC",
"apex-rollup@1.6.20": "04t6g000008OanPAAS",
"apex-rollup@1.6.21": "04t6g000008OatsAAC",
"apex-rollup@1.6.22": "04t6g000008OavAAAS"
"apex-rollup@1.6.22": "04t6g000008OavAAAS",
"apex-rollup@1.6.23": "04t6g000008OawIAAS"
}
}

0 comments on commit d8ff7fa

Please sign in to comment.