Skip to content

Commit

Permalink
groupByWithDefaultFields
Browse files Browse the repository at this point in the history
  • Loading branch information
pgajek2 committed Sep 26, 2023
1 parent c1d6843 commit 68ebda5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ public virtual inherited sharing class SOQL implements Queryable {

public Set<String> toValuesOf(SObjectField fieldToExtract) {
// https://salesforce.stackexchange.com/questions/393308/get-a-list-of-one-column-from-a-soql-result
builder.fields.clearAllFields(); // other fields not needed
return new Map<String, SObject>(with(fieldToExtract, 'Id').groupBy(fieldToExtract).toAggregated()).keySet();
}

Expand Down
13 changes: 13 additions & 0 deletions force-app/main/default/classes/SOQL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,19 @@ private class SOQL_Test {
);
}

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

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

@IsTest
static void orderByString() {
// Test
Expand Down

0 comments on commit 68ebda5

Please sign in to comment.