diff --git a/force-app/main/default/classes/SOQL.cls b/force-app/main/default/classes/SOQL.cls index cb29732..0044e1e 100644 --- a/force-app/main/default/classes/SOQL.cls +++ b/force-app/main/default/classes/SOQL.cls @@ -547,6 +547,7 @@ public virtual inherited sharing class SOQL implements Queryable { public Set 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(with(fieldToExtract, 'Id').groupBy(fieldToExtract).toAggregated()).keySet(); } diff --git a/force-app/main/default/classes/SOQL_Test.cls b/force-app/main/default/classes/SOQL_Test.cls index 4f25d74..eff7023 100644 --- a/force-app/main/default/classes/SOQL_Test.cls +++ b/force-app/main/default/classes/SOQL_Test.cls @@ -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