• mhanafi
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

I created a trigger to check for duplicate and raise an error.

It woks fine for Admin users.

Howevere when run by sales users they have the following error : 

 

Review all error messages below to correct your data.
Apex trigger setOwnerFromPrevious caused an unexpected exception, contact your administrator: setOwnerFromPrevious: 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. 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):

 

 

 

Trigger DuplicateLead on Lead (before insert) {
Map<String, Lead> leadMap= new Map<String, Lead>();

for (Lead lead : System.Trigger.new) {
if(lead.Email !='' && lead.Email != null )
leadMap.put(lead.Email, lead);
}
if(leadMap.size()>0){
for (Lead lead : [SELECT Email,OwnerId,Account_Application__c,LeadSource,Account_Application_Date__c,ConvertedDate FROM Lead WHERE Email IN :leadMap.KeySet() Limit 1000])
{
Lead newLead = leadMap.get(lead.Email);
if(newLead!=null){
newLead.Email.addError('Email already exist');
}
}
}
}
 

 Any help will be greatly appreciated.

Message Edited by mhanafi on 06-17-2009 05:58 AM

I created a trigger to check for duplicate and raise an error.

It woks fine for Admin users.

Howevere when run by sales users they have the following error : 

 

Review all error messages below to correct your data.
Apex trigger setOwnerFromPrevious caused an unexpected exception, contact your administrator: setOwnerFromPrevious: 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. 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):

 

 

 

Trigger DuplicateLead on Lead (before insert) {
Map<String, Lead> leadMap= new Map<String, Lead>();

for (Lead lead : System.Trigger.new) {
if(lead.Email !='' && lead.Email != null )
leadMap.put(lead.Email, lead);
}
if(leadMap.size()>0){
for (Lead lead : [SELECT Email,OwnerId,Account_Application__c,LeadSource,Account_Application_Date__c,ConvertedDate FROM Lead WHERE Email IN :leadMap.KeySet() Limit 1000])
{
Lead newLead = leadMap.get(lead.Email);
if(newLead!=null){
newLead.Email.addError('Email already exist');
}
}
}
}
 

 Any help will be greatly appreciated.

Message Edited by mhanafi on 06-17-2009 05:58 AM