Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed Nov 5, 2023
1 parent 38a17e1 commit fb22633
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<String> selectFields = new List<String>();

removeNotGroupedFields();

selectFields.addAll(fields);
selectFields.addAll(aggregateFunctions);

Expand All @@ -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);
Expand Down

0 comments on commit fb22633

Please sign in to comment.