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
Vishnu_SFDCVishnu_SFDC 

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 salesforce.com 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 : System.Trigger.new) {       
      if(leadORE.RecordTypeId=='012i0000000VWJS')
      {
        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
            }          
       }

if(leadMapORE.size()!=0)
     {
    // 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 != 'noemail@noemail.com')
     {
    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 noemail@noemail.com');
        System.debug(Logginglevel.Finest,'MsgTxt');
              }      
     else                                                                        
     {
     newLead.Duplicate_lead__c = true;
     newLead.Duplicate_lead_Id__c = lead.Id;
     }
     }
    }
     }


Thnaks.
Ramu_SFDCRamu_SFDC
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.