I am receiving a System.QueryException when searching for contacts by phone number in an APEX class:
An error occurred at element myRule_1_A2 (FlowActionCall). An Apex error occurred: 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)
My query looks like this:
String phoneNumber = 55555555555 List<Contact> contacts = new List<Contact>(); contacts = [ Select Id, Name FROM Contact WHERE HomePhone = :phoneNumber OR MobilePhone = :phoneNumber ];
My organization has more than 100,000 contacts (actual number around 250,000). Can someone recommend a way of improving this query or bypassing the QueryException I am receiving.