You need to sign in to do that
Don't have an account?
Bulkify the code
I'm still a fledgling Apex man right now. I am trying to use a modified set of code from the following URL, but even the pre-existing code does not work llwhen deployed due to the error listed.
http://www.salesforce.com/docs/developer/cookbook/Content/apex_dedupe.htm
trigger leadDuplicatePreventer on Lead(before insert, before update) { Map<String, Lead> leadMap = new Map<String, Lead>();
for (Lead lead : System.Trigger.new) { // Make sure we don't treat an email address that // isn't changing during an update as a duplicate. if ((lead.Email != null) && (System.Trigger.isInsert || (lead.Email != System.Trigger.oldMap.get(lead.Id).Email))) { // Make sure another new lead isn't also a duplicate if (leadMap.containsKey(lead.Email)) { lead.Email.addError('Another new lead has the ' + 'same email address.'); } else { leadMap.put(lead.Email, lead); } } } // Using a single database query, find all the leads in // the database that have the same email address as any // of the leads being inserted or updated. for (Lead lead : [SELECT Email FROM Lead WHERE Email IN :leadMap.KeySet()]) { Lead newLead = leadMap.get(lead.Email); newLead.Email.addError('A lead with this email ' + 'address already exists.'); } }
Error: Failure Message: "System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, leadDuplicatePreventer: execution of BeforeInsert caused by: System.QueryException: Non-selective query against large object type (more than 100000 rows). Consider an indexed filter or contact sales...
As much as I can write code and alter existing triggers, and as much as I keep reading this is "simply" a problem with not using an Indexed field, I have no clue what to do. I've tried adding a Select to the MAP statement with a WHERE that references either Email or Name, but it doesn't help - same error.
Help?
The code being played with is even more simple:
I dont see any problem.
1.May be some validation is creating a problem .Check it
2.
I'm checking one of the key test classes. The beginning of the class has:
The error in question is mentioning the insert line of this code. :-/