GROUP BY
Group of records instead of processing many individual records.
SELECT LeadSource
FROM Lead
GROUP BY LeadSource
public inherited sharing class LeadSelector implements SOQL.Selector {
public static SOQL query() {
return SOQL.of(Lead.SObjectType);
}
}
public with sharing class MyController {
public static List<AggregateResult> getGroupedLeads() {
return LeadSelector.query()
.with(Lead.LeadSource)
.groupBy(Lead.LeadSource)
.toAggregated();
}
}