• NYNick
  • NEWBIE
  • 0 Points
  • Member since 2010

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

Hi,

Can anyone assist me or guide me in the right direction?

 

Currently there are some members in my organization who forget to do a quick search for a lead or contact before creating a new contact.  Is it possible to create a rule or formula which will not allow a user to be created if the email is already in the system?

 

Greatly appreciate any feedback.

 

Nick

  • April 07, 2010
  • Like
  • 0

Hi,

Can anyone assist me or guide me in the right direction?

 

Currently there are some members in my organization who forget to do a quick search for a lead or contact before creating a new contact.  Is it possible to create a rule or formula which will not allow a user to be created if the email is already in the system?

 

Greatly appreciate any feedback.

 

Nick

  • April 07, 2010
  • Like
  • 0

I'm trying to implement a trigger to prevent duplicate contacts from being entered.  The criteria is that it should prevent the contact from being added if the first and last name and any of the phone numbers match those of an existing contact, or if the email matches an existing contact regardless of whether the name matches or not.

 

Here's the code I'm trying to get it to accept:

 trigger ContactDuplicateTrigger on Contact (before insert) {
for (Contact c : Trigger.new){
Contact[] contacts= [select id from Contact where
    (FirstName = :c.FirstName and LastName = :c.LastName) and
    (Phone=:c.Phone or MobilePhone=:c.MobilePhone or HomePhone=:c.HomePhone or OtherPhone=:c.OtherPhone or Home_Phone_2__c=:c.Home_Phone_2__c)
    or Email = :c.Email];
if (contacts.size() > 0) {
c.LastName.addError('Contact cannot be created - Contact already exists with the same email or name-phone combination.');
}
}
}

 

Here's the error it gives me:

 

 Error: Compile Error: expecting right square bracket, found 'or' at line 6 column 4

 

I tried adding in parentheses to group the logic correctly, but I wonder if Apex support it.  Can someone help me with the syntax to enforce the desired logic?

 

Thank you!