From fb22633aef8457534cbc913a2a21ff8ab7425fc4 Mon Sep 17 00:00:00 2001 From: Piotr PG Gajek Date: Sun, 5 Nov 2023 20:42:27 +0100 Subject: [PATCH] refactoring --- force-app/main/default/classes/SOQL.cls | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/force-app/main/default/classes/SOQL.cls b/force-app/main/default/classes/SOQL.cls index f2227f9..062b7f1 100644 --- a/force-app/main/default/classes/SOQL.cls +++ b/force-app/main/default/classes/SOQL.cls @@ -836,9 +836,9 @@ public virtual inherited sharing class SOQL implements Queryable { } public void with(String commaSeparatedFields) { - // To avoid field duplicates in query - for (String splitedField : commaSeparatedFields.split(',')) { - String field = splitedField.trim(); + // Added to Set to avoid field duplicates in query + for (String splittedField : commaSeparatedFields.split(',')) { + String field = splittedField.trim(); if (isAggregateFunction(field)) { aggregateFunctions.add(field); } else { @@ -889,11 +889,10 @@ public virtual inherited sharing class SOQL implements Queryable { } if (!groupedFields.isEmpty() || !aggregateFunctions.isEmpty()) { - // To avoid "Field must be grouped or aggregated" error - removeNotGroupedFields(); - List selectFields = new List(); + removeNotGroupedFields(); + selectFields.addAll(fields); selectFields.addAll(aggregateFunctions); @@ -904,6 +903,7 @@ public virtual inherited sharing class SOQL implements Queryable { } public void removeNotGroupedFields() { + // To avoid "Field must be grouped or aggregated" error for (String field : fields) { if (!groupedFields.contains(field)) { fields.remove(field);