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

Error:execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact about custom indexing.

Thanks In Advance.
I am geting the above error for my query. i have more than 200k records in our instance.

for (Lead leadORE : {       
        if ((leadORE.Email != null) &&
                (System.Trigger.isInsert ||
                (leadORE.Email !=System.Trigger.oldMap.get(leadORE.Id).Email))) {      
            if (leadMapORE.containsKey(leadORE.Email)) {
                leadORE.Email.addError('Another new lead has the same email Address.');
            } else {
                leadMapORE.put(leadORE.Email, leadORE);                            //add email to email list

    // Query for all the leads with same email address in the email list for ORE Record Type.
   List<Lead> phoneore = new list<Lead>();
    for (Lead lead : [SELECT Email,Name,email_notification__c FROM Lead WHERE Email IN :leadMapORE.KeySet() and RecordTypeId='012i0000000VWJS' and Email!='' ]) {  
    Lead newLead = leadMapORE.get(lead.Email);
    if(newLead.Email != '')
    if(newLead.email_notification__c == false)                                   
        newLead.addError(' A lead with this email  already exists -' + lead.Name + '.  If you do not know the Email use');
     newLead.Duplicate_lead__c = true;
     newLead.Duplicate_lead_Id__c = lead.Id;

To begin with please remove the select query out of for loops. I see that the inner for loop is dong a select query for each and every record on the parent for loop query this might cause governor limits errors.