From 5d01b00ea5bd4f5d95fe73fa1a4b36835e1e5c5f Mon Sep 17 00:00:00 2001 From: Piotr PG Gajek Date: Wed, 31 May 2023 20:46:54 +0200 Subject: [PATCH] refactoring --- force-app/main/default/classes/SOQL.cls | 31 ++++++++------------ force-app/main/default/classes/SOQL_Test.cls | 12 -------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/force-app/main/default/classes/SOQL.cls b/force-app/main/default/classes/SOQL.cls index d11c7df8..fbb85213 100644 --- a/force-app/main/default/classes/SOQL.cls +++ b/force-app/main/default/classes/SOQL.cls @@ -51,18 +51,14 @@ public inherited sharing class SOQL implements Queryable { SOQL with(SObjectField field1, SObjectField field2, SObjectField field3); SOQL with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4); SOQL with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5); - SOQL with(Set fields); - SOQL with(List fields); - - SOQL with(String fields); - + SOQL with(List fields); // For more than 5 fields + SOQL with(String fields); // Dynamic SOQL SOQL with(String relationshipName, SObjectField field); SOQL with(String relationshipName, SObjectField field1, SObjectField field2); SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3); SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4); SOQL with(String relationshipName, SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5); - SOQL with(String relationshipName, List fields); - + SOQL with(String relationshipName, List fields); // For more than 5 fields SOQL with(SubQuery subQuery); // SOQL.SubQuery SOQL count(); @@ -77,7 +73,7 @@ public inherited sharing class SOQL implements Queryable { SOQL teamScope(); SOQL whereAre(FilterClause conditions); // SOQL.FilterGroup or SOQL.Filter - SOQL whereAre(String conditions); // conditions to evaluate + SOQL whereAre(String conditions); // Conditions to evaluate SOQL groupBy(SObjectField field); SOQL groupByRollup(SObjectField field); @@ -134,7 +130,7 @@ public inherited sharing class SOQL implements Queryable { SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3); SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4); SubQuery with(SObjectField field1, SObjectField field2, SObjectField field3, SObjectField field4, SObjectField field5); - SubQuery with(List fields); + SubQuery with(List fields); // For more than 5 fields SubQuery with(String relationshipName, List fields); SubQuery whereAre(FilterClause conditions); // SOQL.FilterGroup or SOQL.Filter @@ -177,18 +173,19 @@ public inherited sharing class SOQL implements Queryable { Filter startsWith(String value); // LIKE :value + '%' Filter isIn(Set inSet); // IN :inSet Filter isIn(List inList); // IN :inList + Filter isIn(JoinQuery joinQuery); // SOQL.JoinQuery Filter notIn(Set inSet); // NOT IN :inSet Filter notIn(List inList); // NOT IN :inList - - Filter isIn(JoinQuery joinQuery); // SOQL.JoinQuery Filter notIn(JoinQuery joinQuery); // SOQL.JoinQuery - Filter removeWhenNull(); + Filter removeWhenNull(); // Condition will be removed for value = null } public interface SoqlFiltersGroup { // SOQL.FilterGroup FilterGroup add(FilterClause condition); // SOQL.Filter or SOQL.FilterGroup - FilterGroup anyConditionMatching(); // Join with OR + + FilterGroup anyConditionMatching(); // All group filters will be join by OR + FilterGroup conditionLogic(String order); } @@ -220,6 +217,8 @@ public inherited sharing class SOQL implements Queryable { mock.setStaticResourceMock(mockId, staticResource); } + // Config + private static Mock mock = new Mock(); private QueryBuilder builder; @@ -257,10 +256,6 @@ public inherited sharing class SOQL implements Queryable { return with(field1).with(field2).with(field3).with(field4).with(field5); } - public SOQL with(Set fields) { - return with(new List(fields)); - } - public SOQL with(List fields) { builder.fields.with(fields); return this; @@ -517,8 +512,6 @@ public inherited sharing class SOQL implements Queryable { return whereAre(Filter.id().isIn(records)); } - // Config - public interface QueryClause { String build(); } diff --git a/force-app/main/default/classes/SOQL_Test.cls b/force-app/main/default/classes/SOQL_Test.cls index 999fc99e..13f9d096 100644 --- a/force-app/main/default/classes/SOQL_Test.cls +++ b/force-app/main/default/classes/SOQL_Test.cls @@ -100,18 +100,6 @@ private class SOQL_Test { Assert.areEqual('SELECT Id, Name, BillingCity, AccountNumber, AccountSource FROM Account', soql); } - @IsTest - static void withSetOfFields() { - // Test - String soql = SOQL.of(Account.SObjectType) - .with(new Set{ - Account.Name, Account.BillingCity - }).toString(); - - // Verify - Assert.areEqual('SELECT Name, BillingCity FROM Account', soql); - } - @IsTest static void withListOfFields() { // Test