Loading

Make a SOQL query selective by marking a field as External ID or Unique

Data pubblicazione: Oct 13, 2022
Descrizione
If you run into a "Non-selective query against large object type" error when performing a SOQL query or it takes a long time to run, you may make it selective if it filters by a Text field by marking it as External ID.

 
Risoluzione
Salesforce will automatically create an index on a field marked as External ID. If the field is not part of a managed package, contact your system administrator for assistance.

When a Text field is marked as External ID it gets automatically indexed, so the query optimizer will check if its index can be leveraged to drive the query execution. This may help for instance if a query similar to the one shown below is used if less than 10% of the fields have their TextField__c set to 'value'. For more information on SOQL optimization check Make SOQL query Selective.

SELECT Name FROM Account WHERE TextField__c = 'value'

NOTES:
a) Uniqueness is not enforced when a field is marked as External ID.
b) Uniqueness is enforced when a field is marked as Unique. In this case Salesforce will create an index on the field too.
c) By marking a field as External ID, you can also use it to perform an upsert() operation if needed.
 
Numero articolo Knowledge

000383981

 
Caricamento
Salesforce Help | Article