You need to sign in to do that
Don't have an account?
DaveFF
Non-selective query on standard indexed field
I have the following code in a trigger on Account (after update). It's a bit of a hack because I want certain formula fields on certain Contacts to sync to Mailchimp, so their last modified date needs to be touched. I'm now (a week or two later) unable to Update a new field on Opportunities using the Data Loader, as an error down the chain of triggers says "System.QueryException: Non-selective query against large object type (more than 200000 rows)" for this.
Why is this query non-selective, and what can I do to make it better? (Using record type IDs rather than DeveloperNames? Splitting out the last WHERE clause into a separate preliminary query?)
List<Contact> teachers = [ SELECT Id FROM Contact WHERE AccountId IN :schoolIds AND RecordType.DeveloperName LIKE 'Client%' AND Account.RecordType.DeveloperName = 'School_or_College' ];The query should only ever return less than 100 rows. The table contains ~215k rows. I guard against emptiness or presence of nulls in schoolIds, which should be a very small set (most likely only 1). Consulting this cheat sheet and Setup/Customize/Contacts/Fields, I note that lookups and record types are indexed. I don't see any of the automatic exceptions to index selectivity- I'm tempted to suspect the LIKE clause but the wildcard is at the end.
Why is this query non-selective, and what can I do to make it better? (Using record type IDs rather than DeveloperNames? Splitting out the last WHERE clause into a separate preliminary query?)
https://help.salesforce.com/articleView?id=000002493&type=1
Let me know if this helps :)
Thanks!
Amit Singh
All Answers
https://help.salesforce.com/articleView?id=000002493&type=1
Let me know if this helps :)
Thanks!
Amit Singh
That link I don't think will help me- as I'm already selecting a small subset of rows, and the columns I'm working with on Contact itself are standard and already indexed.
Thanks!