I am getting the following Error. works fine in DEV org but throwing error in UAT. Please suggest me as I was unable to move forward.
The Actual Error is
The first validation error encountered was "Apex trigger OpportunityObject caused an unexpected exception, contact your administrator: OpportunityObject: execution of BeforeUpdate caused by: System.QueryException: Non-selective query against large object type (more than 200000 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): Class.OpportunityValidator.ValidateOCR_OnOppStageChange: line 14, column 1".
public class OpportunityValidator {
public static void ValidateOCR_OnOppStageChange(List < Opportunity > newOppsForUpdate, Map < Id, Opportunity > mapOldOpps) {
if (Validator_cls.isOCRfirstRun()) {
Map < String, OCRValidationRequiredRecordTypes__c > mapOCRRequiredRecordTypes = OCRValidationRequiredRecordTypes__c.getAll();
Map < String, OCRValidationRequiredStages__c > mapOCRRequiredStages = OCRValidationRequiredStages__c.getAll();
//Map < Id, String > mapRecordtypeIdName = new Map< Id, String> ();
Map < Id, Opportunity > mapIdOppRecords = new Map < Id, Opportunity > ();
for (Opportunity Op: [SELECT Id,OppLineItemsCount__c, (SELECT Id FROM Opportunitylineitems) FROM Opportunity WHERE
StageName IN: mapOCRRequiredStages.keySet() AND Status__c != 'Closed'
AND
Opportunity.recordtype.Name IN: mapOCRRequiredRecordTypes.keyset() AND
Id NOT IN(SELECT Opportunityid FROM OpportunityContactRole) AND Id IN: newOppsForUpdate
]) {
if ((mapOldOpps.get(Op.id).OppLineItemsCount__c == op.Opportunitylineitems.size() && op.opportunitylineitems.size() > 0)) {
system.debug('----Inside If------OCR');
mapIdOppRecords.put(op.id, op);
}
}
for (opportunity Op: newOppsForUpdate) {
system.debug('Op.recordtype: ' + Op);
if (mapIdOppRecords.get(Op.Id) != NULL) {
Op.addError(' Contact Role is Mandatory ');
}
}
} // End of isOCRfirstRun If condition
} // End of ValidateOCR_OnOppStageChange
} // End of OpportunityValidator