You need to sign in to do that
Don't have an account?

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