function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MikeCampMikeCamp 

System.QueryException: Non-selective query against large object type with indexed field (Unique and External ID)

I randomly get this error in a trigger and the field(RPRegistrationID__c) on the custom object(RP_Registration__c) that I am querying is indexed(set as Unique and External ID)  Any sugestions on what is causing this?
Here is the code
if(!surveyUpdates.isEmpty()){
            Map<string,ID> regIDMap = new Map<string,ID>(); 
            for (RP_Registration__c thisReg : [SELECT Id, RPRegistrationID__c from RP_Registration__c
                where RPRegistrationID__c in :surveyUpdates]) {
                regIDMap.put(thisReg.RPRegistrationID__c,thisReg.ID);
            }

            //update survey to point registration
            for(Survey__c thisSurvey : surveys) {
                if(regIDMap.containsKey(thisSurvey.RPRegistrationID__c)){
                    thisSurvey.Registration__c = regIDMap.get(thisSurvey.RPRegistrationID__c);
                }
            }
Best Answer chosen by MikeCamp
MikeCampMikeCamp
I found that some of the Survey__c object records are coming in with a null in the RPRegistrationID__c field (used to populate the surveyUpdates list),