From fb94e973f1125e19ccd928681a93621592cfba91 Mon Sep 17 00:00:00 2001 From: James Simone <16430727+jamessimone@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:06:14 -0400 Subject: [PATCH] Fixes an issue reported by Katherine West where rollup ordering wasn't being properly applied --- ....Integration_NumberValue_FIRST.md-meta.xml | 29 +++++++++++++++++++ rollup/core/classes/RollupCalculator.cls | 3 +- rollup/core/classes/RollupRepository.cls | 3 +- sfdx-project.json | 9 ++---- 4 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 extra-tests/customMetadata/RollupOrderBy.Integration_NumberValue_FIRST.md-meta.xml diff --git a/extra-tests/customMetadata/RollupOrderBy.Integration_NumberValue_FIRST.md-meta.xml b/extra-tests/customMetadata/RollupOrderBy.Integration_NumberValue_FIRST.md-meta.xml new file mode 100644 index 00000000..fa49e308 --- /dev/null +++ b/extra-tests/customMetadata/RollupOrderBy.Integration_NumberValue_FIRST.md-meta.xml @@ -0,0 +1,29 @@ + + + + false + + FieldName__c + NumberField__c + + + NullSortOrder__c + NULLS FIRST + + + Ranking__c + 1.0 + + + Rollup__c + RollupIntegrationChildRollupText + + + SortOrder__c + Ascending + + diff --git a/rollup/core/classes/RollupCalculator.cls b/rollup/core/classes/RollupCalculator.cls index b4be10b7..82e7e8e4 100644 --- a/rollup/core/classes/RollupCalculator.cls +++ b/rollup/core/classes/RollupCalculator.cls @@ -321,8 +321,9 @@ public without sharing abstract class RollupCalculator { protected List winnowItems(List items, Map oldCalcItems) { List orderBys = this.metadata?.LimitAmount__c != null && this.metadata.RollupOrderBys__r.isEmpty() ? new List{ new RollupOrderBy__mdt(FieldName__c = 'Id', Ranking__c = 0) } - : this.metadata.RollupOrderBys__r; + : new List(this.metadata.RollupOrderBys__r); if (orderBys.isEmpty() == false) { + orderBys.sort(new RollupRepository.OrderBySorter()); items.sort(new RollupCalcItemSorter(orderBys)); } List winnowedItems = new List(); diff --git a/rollup/core/classes/RollupRepository.cls b/rollup/core/classes/RollupRepository.cls index 471dbe9a..18147540 100644 --- a/rollup/core/classes/RollupRepository.cls +++ b/rollup/core/classes/RollupRepository.cls @@ -128,7 +128,7 @@ public without sharing class RollupRepository implements RollupLogger.ToStringOb SharingMode__c, ShouldRunWithoutCustomSettingEnabled__c, SplitConcatDelimiterOnCalcItem__c, - (SELECT Id, FieldName__c, NullSortOrder__c, Ranking__c, SortOrder__c FROM RollupOrderBys__r), + (SELECT Id, DeveloperName, FieldName__c, NullSortOrder__c, Ranking__c, SortOrder__c FROM RollupOrderBys__r), RollupGrouping__r.Id, RollupGrouping__r.RollupOperation__c FROM Rollup__mdt @@ -149,7 +149,6 @@ public without sharing class RollupRepository implements RollupLogger.ToStringOb meta.GroupByRowStartDelimiter__c = meta.GroupByRowStartDelimiter__c?.unescapeJava(); meta.SharingMode__c = meta.SharingMode__c ?? RollupMetaPicklists.SharingMode.SystemLevel; meta.UltimateParentLookup__c = meta.UltimateParentLookup__r.QualifiedApiName; - meta.RollupOrderBys__r.sort(new OrderBySorter()); } return matchingMetadata; diff --git a/sfdx-project.json b/sfdx-project.json index 2ae33484..5764331d 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -5,8 +5,8 @@ "package": "apex-rollup", "path": "rollup", "scopeProfiles": true, - "versionName": "Fixes parentRecordIdForEmptyChildrenCollections flow case", - "versionNumber": "1.6.34.0", + "versionName": "Fixes Rollup Order By sorting to always be deterministic", + "versionNumber": "1.6.35.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": { @@ -101,12 +101,9 @@ "Apex Rollup - Rollup Callback@0.0.3-0": "04t6g000008Sis0AAC", "Nebula Logger - Core@4.14.4-optionally-auto-call-lightning-logger-lwc": "04t5Y0000015oRNQAY", "apex-rollup": "0Ho6g000000TNcOCAW", - "apex-rollup@1.6.28": "04t6g000008ObN8AAK", - "apex-rollup@1.6.29": "04t6g000008ObNNAA0", - "apex-rollup@1.6.30": "04t6g000008ObVhAAK", "apex-rollup@1.6.31": "04t6g000008ObblAAC", "apex-rollup@1.6.32": "04t6g000008ObbvAAC", "apex-rollup@1.6.33": "04t6g000008ObeQAAS", "apex-rollup@1.6.34": "04t6g000008OfJfAAK" } -} +} \ No newline at end of file