From e1f51cfe70c2f51b396c888f065e547504f63281 Mon Sep 17 00:00:00 2001 From: Piotr PG Gajek Date: Mon, 13 May 2024 15:18:38 +0200 Subject: [PATCH 1/2] multiple filtergroup fix Signed-off-by: Piotr PG Gajek --- force-app/main/default/classes/SOQL.cls | 2 +- force-app/main/default/classes/SOQL_Test.cls | 37 ++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/force-app/main/default/classes/SOQL.cls b/force-app/main/default/classes/SOQL.cls index 351a501..530e557 100644 --- a/force-app/main/default/classes/SOQL.cls +++ b/force-app/main/default/classes/SOQL.cls @@ -1305,7 +1305,7 @@ public virtual inherited sharing class SOQL implements Queryable { String orderWithSpecialCharacters = getConditionsLogic(); for (Integer i = 0; i < queryConditions.size(); i++) { - orderWithSpecialCharacters = orderWithSpecialCharacters.replace(String.valueOf(i + 1), '{' + i + '}'); + orderWithSpecialCharacters = orderWithSpecialCharacters.replaceFirst(String.valueOf(i + 1), '{' + i + '}'); } return orderWithSpecialCharacters; // e.g ({0} AND ({1} AND {2})) diff --git a/force-app/main/default/classes/SOQL_Test.cls b/force-app/main/default/classes/SOQL_Test.cls index c0af147..d6a78be 100644 --- a/force-app/main/default/classes/SOQL_Test.cls +++ b/force-app/main/default/classes/SOQL_Test.cls @@ -1522,6 +1522,43 @@ private class SOQL_Test { Assert.areEqual('Krakow', binding.get('v3')); } + @IsTest + static void multipleFiltersGroups() { + // Test + SOQL builder = SOQL.of(Account.SObjectType) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('1'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('2'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('3'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('4'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('5'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('6'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('7'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('8'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('9'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('10'))) + .whereAre(SOQL.FilterGroup.add(SOQL.Filter.with(Account.Name).contains('11'))); + + // Verify + String soql = builder.toString(); + Assert.areEqual( + 'SELECT Id FROM Account WHERE (Name LIKE :v1 AND Name LIKE :v2 AND Name LIKE :v3 AND Name LIKE :v4 AND Name LIKE :v5 AND Name LIKE :v6 AND Name LIKE :v7 AND Name LIKE :v8 AND Name LIKE :v9 AND Name LIKE :v10 AND Name LIKE :v11)', + soql + ); + + Map binding = builder.binding(); + Assert.areEqual('%1%', binding.get('v1')); + Assert.areEqual('%2%', binding.get('v2')); + Assert.areEqual('%3%', binding.get('v3')); + Assert.areEqual('%4%', binding.get('v4')); + Assert.areEqual('%5%', binding.get('v5')); + Assert.areEqual('%6%', binding.get('v6')); + Assert.areEqual('%7%', binding.get('v7')); + Assert.areEqual('%8%', binding.get('v8')); + Assert.areEqual('%9%', binding.get('v9')); + Assert.areEqual('%10%', binding.get('v10')); + Assert.areEqual('%11%', binding.get('v11')); + } + @IsTest static void anyConditionMatchingForInnerGroup() { // Test From 77a27f02785e62822e14a1b7ea16209849fc1854 Mon Sep 17 00:00:00 2001 From: Piotr PG Gajek Date: Mon, 13 May 2024 15:22:01 +0200 Subject: [PATCH 2/2] unit test update Signed-off-by: Piotr PG Gajek --- force-app/main/default/classes/SOQL_Test.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/force-app/main/default/classes/SOQL_Test.cls b/force-app/main/default/classes/SOQL_Test.cls index d6a78be..ffa847e 100644 --- a/force-app/main/default/classes/SOQL_Test.cls +++ b/force-app/main/default/classes/SOQL_Test.cls @@ -1541,7 +1541,7 @@ private class SOQL_Test { // Verify String soql = builder.toString(); Assert.areEqual( - 'SELECT Id FROM Account WHERE (Name LIKE :v1 AND Name LIKE :v2 AND Name LIKE :v3 AND Name LIKE :v4 AND Name LIKE :v5 AND Name LIKE :v6 AND Name LIKE :v7 AND Name LIKE :v8 AND Name LIKE :v9 AND Name LIKE :v10 AND Name LIKE :v11)', + 'SELECT Id FROM Account WHERE (Name LIKE :v1) AND (Name LIKE :v2) AND (Name LIKE :v3) AND (Name LIKE :v4) AND (Name LIKE :v5) AND (Name LIKE :v6) AND (Name LIKE :v7) AND (Name LIKE :v8) AND (Name LIKE :v9) AND (Name LIKE :v10) AND (Name LIKE :v11)', soql );