You need to sign in to do that
Don't have an account?

System.QueryException: Non-selective query against large object type (more than 100000 rows)
Hi,
Lately our Case database seemed to have grown so much, that we started getting the excpetion for every Case update attempt:
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
This is the query that triggers this exception:
Map<Id, Case> map_Cases = new Map<Id, Case>([SELECT Id, Account.Renewal_Date__c FROM Case WHERE AccountId != null and AccountId in :set_AccountIds]);
Is AccountId on Case already indexed? If not, can I ask Salesforce support to do it? Will it resolve the problem? And if not, can you think of any other solution? I don't see how I can optimize this query anymore.
Thank you,
Eran
Lately our Case database seemed to have grown so much, that we started getting the excpetion for every Case update attempt:
caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.
Even if a field is indexed a filter might still not be selective when:
1. The filter value includes null (for instance binding with a list that contains null) 2. Data skew exists whereby the number of matching rows is very large (for instance, filtering for a particular foreign key value that occurs many times)
This is the query that triggers this exception:
Map<Id, Case> map_Cases = new Map<Id, Case>([SELECT Id, Account.Renewal_Date__c FROM Case WHERE AccountId != null and AccountId in :set_AccountIds]);
Is AccountId on Case already indexed? If not, can I ask Salesforce support to do it? Will it resolve the problem? And if not, can you think of any other solution? I don't see how I can optimize this query anymore.
Thank you,
Eran
Try with this.
Map<Id, Case> map_Cases = new Map<Id, Case>([SELECT Id, Account.Renewal_Date__c FROM Case WHERE AccountId in :set_AccountIds]);