Skip to content

Commit

Permalink
v1.6.12 - Flow Bugfix for Multiple DML (#559)
Browse files Browse the repository at this point in the history
* Fixes #556 by properly detecting when subsequent DML statements enqueued by Flow triggers should react to deletes

* Re-adding eslint to pipeline - thanks to @codefriar for pointing this out
  • Loading branch information
jamessimone authored Feb 7, 2024
1 parent 8440e44 commit 6c2b7bf
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 50 deletions.
38 changes: 14 additions & 24 deletions Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,33 @@ yarn
npm -i
```

## Before you begin
## Setting Up Your Salesforce Development Environment

### Check your development environment
### Be aware of your development options

This monorepo allows you to develop the app in either a scratch org or in a sandbox or Developer Edition org.
Apex Rollup is a monorepo that contains both the base unlocked package's source code and the source code for various plugin packages. Not _all_ of the code is required to be deployed if you aren't looking to work on plugins, but because the "Apex Rollup - Nebula Logger" plugin relies on [Nebula Logger](https://github.com/jongpie/NebulaLogger/) being installed, you have some choices to make if you want to use the `Push Source To Default Org` and CLI equivalents in a Source Tracking-enabled development environment.

#### For orgs with Source Tracking enabled
You can either:

Install the Nebula Logger version provided in the `sfdx-project.json`'s `packageAliases` attribute. Using the CLI, do it like this:
1. Install the Nebula Logger version provided in the `sfdx-project.json`'s `packageAliases` attribute. Using the CLI, do it like this:

```bash
sf package install -p <package version 04t> -w 30 -r
```

#### For orgs that do not have Source Tracking enabled
or:

Deploy the contents of the `rollup` folder directly with:
2. Deploy the unlocked package source directories:

```bash
sf project deploy start --source-dir ./rollup
sf project deploy start --source-dir ./extra-tests
```

or:

3. Comment out the "Apex Rollup - Nebula Logger" plugin within the `packageDirectories` list in `sfdx-project.json` - this will allow `Push Source...` commands to work. Just remember to uncomment that plugin prior to submitting anything to be reviewed!

### Make sure to assign permissions to your user

The app is available to users that have the two permissions. For development purposes we recommend having at least the two main permission sets assigned to your user. Assign them with these commands:
Expand All @@ -39,27 +44,12 @@ sf org assign permset -n See_Rollup_App
sf org assign permset -n See_Rollup_Button
```

## Ensure all rollup files are installed

Whether you are developing on a sandbox or a new scratch org, please be sure to also deploy the `extra-tests` directory:

```bash
sf project deploy start --source-dir ./extra-tests
```

I've included helper scripts to aid in programmatically testing only Apex Rollup's test classes when developing in a sandbox within the `package.json` file - one need only invoke the tests like such on the command line:

- `yarn test`
- or `npm run test`

Within a scratch org, validating that all of the tests run is as simple as invoking `sfdx force:apex:test:run -w 10`.
## Prior To Submitting A Change/Pull Request

When submitting a pull request, please follow these guidelines:

- there should be no errors when running `npm run scan` or `yarn scan`
- ensure your dependencies have been installed and that any/all file(s) changed have had prettier-apex run on them (usually as simple as enabling "Format On Save" in your editor's options); alternatively you can always format the document in Vs Code using `Shift + Ctrl + F` or `cmd + Shift + F` once you're done writing. Your mileage may vary as to the hotkey if you're using Illuminated Cloud or another text editor; you always have the option of invoking prettier on the command-line
- ensure that tests have been run against a scratch org with multi-currency enabled (you can look at [`scripts/test.ps1`](https://github.com/jamessimone/apex-rollup/blob/main/scripts/test.ps1) to see how the scratch org is created and the currency ISO codes are loaded).
- ensure that any change to production code comes with the addition of tests. It's possible that I will accept PRs where _only_ production-level code is changed, if an optimization is put in place -- but otherwise, try to write a failing test first!
- if you are testing on a scratch org, `sfdx force:source:push` will fail due to the Rollup Nebula Logger Adapter plugin. You can either:
- temporarily comment out that plugin within the `packageDirectories` list in `sfdx-project.json`
- install whichever `04t...` version of Nebula Logger the plugin relies upon by looking at the dependency listed within `sfdx-project.json`'s `packageAliases` object

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=04t6g000008OaO6AAK">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaOuAAK">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaO6AAK">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaOuAAK">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
Expand Down
31 changes: 31 additions & 0 deletions extra-tests/classes/RollupFlowTests.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1033,4 +1033,35 @@ private class RollupFlowTests {
System.assertNotEquals('No records to rollup, returning early', flowOutputs[0].message);
System.assertEquals(null, acc.AnnualRevenue);
}

@IsTest
static void worksWithMultipleDmlWithDeletes() {
Account acc = [SELECT Id FROM Account];
acc.AnnualRevenue = 1;
RollupAsyncProcessor.stubParentRecords = new List<SObject>{ acc };

List<ContactPointAddress> cpas = new List<ContactPointAddress>{
new ContactPointAddress(PreferenceRank = 1, ParentId = acc.Id, Name = 'Non-match 1'),
new ContactPointAddress(PreferenceRank = 2, ParentId = acc.Id, Name = 'Match to be deleted')
};
insert cpas;

ContactPointAddress toDelete = cpas.remove(1);
List<ContactPointAddress> deletedCpas = new List<ContactPointAddress>{ toDelete };

List<Rollup.FlowInput> flowInputs = RollupTestUtils.prepareFlowTest(deletedCpas, 'UPDATE', 'COUNT');
flowInputs[0].oldRecordsToRollup = new List<ContactPointAddress>(deletedCpas);
flowInputs[0].isFullRecordSet = true;
flowInputs[0].calcItemWhereClause = 'PreferenceRank = 2';
flowInputs.addAll(RollupTestUtils.prepareFlowTest(deletedCpas, 'DELETE', 'COUNT'));
flowInputs[1].calcItemWhereClause = 'PreferenceRank = 2';
flowInputs[1].isFullRecordSet = true;

Test.startTest();
Rollup.performRollup(flowInputs);
Test.stopTest();

Account updatedAcc = [SELECT Id, AnnualRevenue FROM Account WHERE Id = :acc.Id];
System.assertEquals(null, updatedAcc.AnnualRevenue);
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apex-rollup",
"version": "1.6.11",
"version": "1.6.12",
"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 Expand Up @@ -49,7 +49,8 @@
"lint:verify": "sfdx scanner:run --target **/lwc/**/*.js,!node_modules/** --engine eslint-lwc --severity-threshold 3 --eslintconfig .eslintrc.json",
"prepare": "husky install && sfdx plugins:link ./node_modules/@salesforce/sfdx-scanner && sfdx plugins:link ./node_modules/@jongpie/sfdx-bummer-plugin",
"prettier": "prettier",
"scan": "sfdx scanner:run --pmdconfig config/pmd-ruleset.xml --target .,!plugins/ExtraCodeCoverage/** --engine pmd --severity-threshold 3",
"scan": "npm run lint:verify && npm run scan:pmd",
"scan:pmd": "sfdx scanner:run --pmdconfig config/pmd-ruleset.xml --target .,!plugins/ExtraCodeCoverage/** --engine pmd --severity-threshold 3",
"scan:graph": "sfdx scanner:run -e sfge -p . --target 'rollup'",
"test": "npm run test:apex && npm run test:lwc",
"test:apex": "sh ./scripts/runLocalTests.sh",
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=04t6g000008OaOBAA0">
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaOzAAK">
<img alt="Deploy to Salesforce"
src="./media/deploy-package-to-prod.png">
</a>

<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaOBAA0">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008OaOzAAK">
<img alt="Deploy to Salesforce Sandbox"
src="./media/deploy-package-to-sandbox.png">
</a>
17 changes: 4 additions & 13 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": "Continuation from v1.6.5 with big CPU time improvements made to Flow-based rollups, particularly for the update record code path",
"versionNumber": "1.1.10.0",
"versionName": "Flow bugfix for flows triggered via Apex that both update AND delete records",
"versionNumber": "1.1.11.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 @@ -21,19 +21,10 @@
"sourceApiVersion": "58.0",
"packageAliases": {
"apex-rollup-namespaced": "0Ho6g000000PBMjCAO",
"apex-rollup-namespaced@1.0.51-0": "04t6g000008C71cAAC",
"apex-rollup-namespaced@1.0.52-0": "04t6g000008C72GAAS",
"apex-rollup-namespaced@1.0.53-0": "04t6g000008C739AAC",
"apex-rollup-namespaced@1.1.0-0": "04t6g000008C7AVAA0",
"apex-rollup-namespaced@1.1.1-0": "04t6g000008OZwdAAG",
"apex-rollup-namespaced@1.1.2-0": "04t6g000008Oa7YAAS",
"apex-rollup-namespaced@1.1.3": "04t6g000008Oa8lAAC",
"apex-rollup-namespaced@1.1.4": "04t6g000008Oa9ZAAS",
"apex-rollup-namespaced@1.1.5": "04t6g000008OaAcAAK",
"apex-rollup-namespaced@1.1.6": "04t6g000008OaFnAAK",
"apex-rollup-namespaced@1.1.7": "04t6g000008OaJQAA0",
"apex-rollup-namespaced@1.1.8": "04t6g000008OaJpAAK",
"apex-rollup-namespaced@1.1.9": "04t6g000008OaLHAA0",
"apex-rollup-namespaced@1.1.10": "04t6g000008OaOBAA0"
"apex-rollup-namespaced@1.1.10": "04t6g000008OaOBAA0",
"apex-rollup-namespaced@1.1.11": "04t6g000008OaOzAAK"
}
}
2 changes: 1 addition & 1 deletion rollup/core/classes/RollupAsyncProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ global virtual without sharing class RollupAsyncProcessor extends Rollup impleme
// calling clear in a loop here might look interesting - and it would be a massive problem if not for the
// bag only responding to the very first clear() invocation. everything after that is a no-op (so, any rollup with more
// than one rollup operation going at a time)
if (rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE) {
if (rollup.triggerContext == System.TriggerOperation.BEFORE_DELETE || rollup.op.name().contains('DELETE')) {
bag.clear();
}
}
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.11';
private static final String CURRENT_VERSION_NUMBER = 'v1.6.12';
private static final LoggingLevel FALLBACK_LOGGING_LEVEL = LoggingLevel.DEBUG;
private static final RollupPlugin PLUGIN = new RollupPlugin();

Expand Down
9 changes: 4 additions & 5 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": "Continuation from v1.6.5 with big CPU time improvements made to Flow-based rollups, particularly for the update record code path",
"versionNumber": "1.6.11.0",
"versionName": "Flow bugfix for flows triggered via Apex that both update AND delete records",
"versionNumber": "1.6.12.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 @@ -100,9 +100,8 @@
"Apex Rollup - Rollup Callback@0.0.3-0": "04t6g000008Sis0AAC",
"Nebula Logger - Core@4.8.0-NEXT-ignore-origin-method": "04t5Y0000015lslQAA",
"apex-rollup": "0Ho6g000000TNcOCAW",
"apex-rollup@1.6.8": "04t6g000008OaJLAA0",
"apex-rollup@1.6.9": "04t6g000008OaJkAAK",
"apex-rollup@1.6.10": "04t6g000008OaLCAA0",
"apex-rollup@1.6.11": "04t6g000008OaO6AAK"
"apex-rollup@1.6.11": "04t6g000008OaO6AAK",
"apex-rollup@1.6.12": "04t6g000008OaOuAAK"
}
}

0 comments on commit 6c2b7bf

Please sign in to comment.