You need to sign in to do that
Don't have an account?
iSqFt_AD
Contact Dupe Preventer - User Receives Error - Any Ideas?
What is it about line 27 that would give the user creating the Contact this error, as well as email me the error?
Error:
Apex script unhandled trigger exception by user/organization: 00560000000rvkR/00D6000000077GT
contactDuplicatePreventer: execution of BeforeUpdate
caused by: System.NullPointerException: Attempt to de-reference a null object
Trigger.contactDuplicatePreventer: line 27, column 1
Trigger:
trigger contactDuplicatePreventer on Contact (before insert, before update) { Map<String, Contact> contactMap = new Map<String, Contact>(); for (Contact contact : System.Trigger.new) { // Make sure we don't treat an email address that // isn't changing during an update as a duplicate. if ((contact.Email != null) && (System.Trigger.isInsert || (contact.Email != System.Trigger.oldMap.get(contact.Id).Email))) { // Make sure another new contact isn't also a duplicate if (contactMap.containsKey(contact.Email)) { contact.Email.addError('Another new Contact has the same email address.'); } else { contactMap.put(contact.Email, contact); } } } // Using a single database query, find all the contacts in // the database that have the same email address as any // of the contacts being inserted or updated. for (Contact contact : [SELECT Email FROM Contact WHERE Email IN :contactMap.KeySet()]) { if(contact.email != null){ Contact newContact = contactMap.get(contact.Email); System.debug('new contact = ' + newContact); System.debug('email = ' + newContact.Email); newContact.Email.addError('A Contact with this email address already exists.');} } }
Thanks!
Try this
All Answers
UPDATE:
So it appears, after talking to the rep, that the issue was she was attempting to edit an existing Contact and give them an email address that is already in Salesforce.
Knowing this, how do I edit the trigger so that this example is covered by an error message, rather than a developer script exception?
Try this.
What is "Integer"? I put this in my sandbox and got this error:
Error: Compile Error: Variable does not exist: i at line 24 column 22
Is there a way to just edit my existing trigger to get it to push an error message rather than the exception?
Thanks for your help.
use integer insted of Integer
Same error. What is "integer" representing?
Try this. I am initializing 'i'
Error: Compile Error: Variable does not exist: isInsert at line 20 column 12
Try this
Thank you kindly!
Any idea why I received almost 50 of these messages in the last 12 hours from this trigger? Thanks!
Apex script unhandled trigger exception by user/organization: 00560000001L3AU/00D6000000077GT
contactDuplicatePreventer: execution of BeforeUpdate
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.contactDuplicatePreventer: line 15, column 1