Describe the solution you'd like
toIdsOf and toValuesOf methods currently fetch all records from database.
If you include COUNT(Id) query function in this query, number of query rows drops drastically, to the size of returned Set.
And there are basically no downsides.
private Set<Id> toIdsOf(String fieldToExtract) {
// https://salesforce.stackexchange.com/questions/393308/get-a-list-of-one-column-from-a-soql-result
this.builder.fields.clearAllFields(); // other fields not needed
this.with('COUNT(Id)');
this.with(fieldToExtract, 'Id');
this.groupBy(fieldToExtract);
this.builder.conditions.addMasterCondition(Filter.with(fieldToExtract).isNotNull());
return new Map<Id, SObject>(this.toAggregated(fieldToExtract)).keySet();
}
Describe the solution you'd like
toIdsOfandtoValuesOfmethods currently fetch all records from database.If you include
COUNT(Id)query function in this query, number of query rows drops drastically, to the size of returned Set.And there are basically no downsides.