Skip to content

Enhance toIdsOf(String fieldToExtract) and toValuesOf(String fieldToExtract) [release v6.8.0] #262

@konwron

Description

@konwron

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();
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions