diff --git a/Contributing.md b/Contributing.md index 8cbdc20b..4bad8dfe 100644 --- a/Contributing.md +++ b/Contributing.md @@ -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 -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: @@ -39,20 +44,7 @@ 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: @@ -60,6 +52,4 @@ When submitting a pull request, please follow these guidelines: - 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 + diff --git a/README.md b/README.md index ed0ecd4e..6990e88d 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,12 @@ As well, don't miss [the Wiki](../../wiki), which includes even more info for co ## Deployment & Setup - + Deploy to Salesforce - + Deploy to Salesforce Sandbox diff --git a/extra-tests/classes/RollupFlowTests.cls b/extra-tests/classes/RollupFlowTests.cls index e38f9e57..7809cbb9 100644 --- a/extra-tests/classes/RollupFlowTests.cls +++ b/extra-tests/classes/RollupFlowTests.cls @@ -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{ acc }; + + List cpas = new List{ + 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 deletedCpas = new List{ toDelete }; + + List flowInputs = RollupTestUtils.prepareFlowTest(deletedCpas, 'UPDATE', 'COUNT'); + flowInputs[0].oldRecordsToRollup = new List(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); + } } diff --git a/package.json b/package.json index 8487d5cd..108aa9c0 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/rollup-namespaced/README.md b/rollup-namespaced/README.md index 811f92e0..b54d775b 100644 --- a/rollup-namespaced/README.md +++ b/rollup-namespaced/README.md @@ -18,12 +18,12 @@ For more info, see the base `README`. ## Deployment & Setup - + Deploy to Salesforce - + Deploy to Salesforce Sandbox diff --git a/rollup-namespaced/sfdx-project.json b/rollup-namespaced/sfdx-project.json index 3e018023..d8573d63 100644 --- a/rollup-namespaced/sfdx-project.json +++ b/rollup-namespaced/sfdx-project.json @@ -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": { @@ -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" } } \ No newline at end of file diff --git a/rollup/core/classes/RollupAsyncProcessor.cls b/rollup/core/classes/RollupAsyncProcessor.cls index d2c8be91..b0524cdd 100644 --- a/rollup/core/classes/RollupAsyncProcessor.cls +++ b/rollup/core/classes/RollupAsyncProcessor.cls @@ -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(); } } diff --git a/rollup/core/classes/RollupLogger.cls b/rollup/core/classes/RollupLogger.cls index 5b181c72..53c5df94 100644 --- a/rollup/core/classes/RollupLogger.cls +++ b/rollup/core/classes/RollupLogger.cls @@ -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(); diff --git a/sfdx-project.json b/sfdx-project.json index b1b1a6b8..b6db738c 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -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": { @@ -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" } } \ No newline at end of file