From 57a9c3f50398a18128e53490ea88d4f61cec1d1b Mon Sep 17 00:00:00 2001 From: William Velzeboer <6429417+wimvelzeboer@users.noreply.github.com> Date: Mon, 19 Jan 2026 09:57:46 +0000 Subject: [PATCH] Add method overload for fflib_ArrayUtils.replaceValues (#70) Adds compatibility with Boolean values --- .forceignore | 4 ++- .gitignore | 4 ++- .../classes/utils/fflib_ArrayUtils.cls | 30 +++++++++++++++++++ .../classes/utils/fflib_ArrayUtilsTest.cls | 28 +++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/.forceignore b/.forceignore index f492b32..deec027 100755 --- a/.forceignore +++ b/.forceignore @@ -16,4 +16,6 @@ package.xml **/*.ts **/tsconfig*.json **/*.tsbuildinfo -**/eslint.config.mjs \ No newline at end of file +**/eslint.config.mjs + +**/graphql.config.yml \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8ef4cd9..fae1565 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,6 @@ sfdx-source/apex-extensions-examples target/ /.illuminatedCloud/ **/tsconfig*.json -**/*.tsbuildinfo \ No newline at end of file +**/*.tsbuildinfo + +**/graphql.config.yml \ No newline at end of file diff --git a/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls index 559d658..b6f6040 100644 --- a/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls +++ b/sfdx-source/apex-extensions/main/default/classes/utils/fflib_ArrayUtils.cls @@ -400,6 +400,36 @@ public class fflib_ArrayUtils return result; } + /** + * Takes two maps and replaces the value of the source with the value of the replacement, + * where the source value matches the replacement key. + * The value will become null if the source value does not exists as key in replacement map + * + * @param source The map to replace its value + * @param replacement The map to use its value for replacement + * + * @return Returns a Map<{Source-key} Id, {Replacement-value} Id> + */ + public static Map replaceValue(Map source, Map replacement) + { + Map result = new Map(); + for (Id keyId : source.keySet()) + { + Id sourceValue = source.get(keyId); + + if (replacement.containsKey(sourceValue)) + { + result.put(keyId, replacement.get(sourceValue)); + } + else + { + // There is no replacement value for this keyId + result.put(keyId, null); + } + } + return result; + } + /** * Takes two maps and replaces the value of the source with the values of the replacement, * where the source value matches the replacement key. diff --git a/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls b/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls index 17d1f33..4236bc9 100644 --- a/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls +++ b/sfdx-source/apex-extensions/tests/classes/utils/fflib_ArrayUtilsTest.cls @@ -322,6 +322,34 @@ private class fflib_ArrayUtilsTest System.Assert.isNull(result.get(accountIdC)); } + @IsTest + static void itShouldReplaceValueInTheMap_boolean() + { + Id accountIdA = fflib_IDGenerator.generate(Schema.Account.SObjectType); + Id accountIdB = fflib_IDGenerator.generate(Schema.Account.SObjectType); + Id accountIdC = fflib_IDGenerator.generate(Schema.Account.SObjectType); + Id contactIdA = fflib_IDGenerator.generate(Schema.Contact.SObjectType); + Id contactIdB = fflib_IDGenerator.generate(Schema.Contact.SObjectType); + Map source = new Map + { + accountIdA => contactIdA, + accountIdB => contactIdB, + accountIdC => fflib_IDGenerator.generate(Schema.Contact.SObjectType) + }; + Map replacement = new Map + { + contactIdA => true, + contactIdB => false + }; + + Map result = fflib_ArrayUtils.replaceValue(source, replacement); + + System.Assert.areEqual(3, result.size()); + System.Assert.isTrue(result.get(accountIdA)); + System.Assert.isFalse(result.get(accountIdB)); + System.Assert.isNull(result.get(accountIdC)); + } + @IsTest static void itShouldReturnAllValuesForTheGivenIds() {