Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/v3.4.0 #135

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,9 @@ public virtual inherited sharing class SOQL implements Queryable {
if (!groupedFields.isEmpty() || !aggregateFunctions.isEmpty()) {
List<String> selectFields = new List<String>();

removeNotGroupedFields();
// To avoid "Field must be grouped or aggregated" error
// retain only grouped or aggregated fields
fields.retainAll(groupedFields);

selectFields.addAll(fields);
selectFields.addAll(aggregateFunctions);
Expand All @@ -1129,15 +1131,6 @@ public virtual inherited sharing class SOQL implements Queryable {

return 'SELECT ' + String.join(fields, ', ');
}

public void removeNotGroupedFields() {
// To avoid "Field must be grouped or aggregated" error
for (String field : fields) {
if (!groupedFields.contains(field)) {
fields.remove(field);
}
}
}
}

private class SoqlSubQuery implements SubQuery {
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/classes/SOQL.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
14 changes: 14 additions & 0 deletions force-app/main/default/classes/SOQL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,20 @@ private class SOQL_Test {
Assert.areEqual('SELECT LeadSource FROM Lead GROUP BY LeadSource', soql);
}

@IsTest
static void groupByWithDefaultFieldsAndAggregateFunction() {
// Test
String soql = SOQL.of(Lead.SObjectType)
.with(Lead.FirstName, Lead.LastName, Lead.Email)
.count(Lead.Name)
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.toString();

// Verify
Assert.areEqual('SELECT LeadSource, COUNT(Name) FROM Lead GROUP BY LeadSource', soql);
}

@IsTest
static void havingFilterWithSObjectField() {
// Test
Expand Down
2 changes: 1 addition & 1 deletion force-app/main/default/classes/SOQL_Test.cls-meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<apiVersion>62.0</apiVersion>
<status>Active</status>
</ApexClass>
Loading