function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tywalker2276tywalker2276 

Preventing Duplicate Contacts

Does anybody know of a way to prevent users from entering duplicate contacts?

 

Thanks,

 

Tyler

Ispita_NavatarIspita_Navatar

Salesforce does not prevent entry of duplicate contacts. In case you want to implement that then you need to do the following:-

1. First define a criterion for duplicity of contacts , will it be name? (but there are different people with same name), so may be email address will be a good identifying factor for duplicate contact, you may even use phone number.

2. Once you have decided the criterion you may write a simple trigger to check the system to existence of duplicate on contact creation, if say any provided email address exists then raise an error in the trigger and inform the user appropriately.

There are some apps on appexchange which provide this functionality , you may even use that.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

tywalker2276tywalker2276

I must apologize, but I am fairly new to this.  How exactly would I go about writing a trigger?  In regard to the appexchange, is there app in specific that you would recommend?

Marco_MaltesiMarco_Maltesi

hi,

i am also new to salesforce, but it's no so difficult.

after installing salesforce plugin to eclipse(you can find many tutorials),open a new Force.com project (connect to your organisation sandBox or production)

create new apex trigger

and copy this:

trigger

Duplicate2 onContact (beforeinsert, beforeupdate) {

{

set

<string> setFirstNames=newset<string>();

set

<string> setLastNames=newset<string>();

list

<contact> listnames=newlist<contact>();

for

(contact acc:trigger.new)

{

setFirstNames.add(acc.FirstName);

setLastNames.add(acc.LastName);

}

listnames=[

select FirstName,LastName,id from contact where FirstName in:setFirstNames and LastName in:setLastNames];

if

(trigger.isinsert)

{

for

(contact acc:trigger.new)

{

for

(contact dup:listnames)

{

if

(acc.FirstName==dup.FirstName && acc.LastName==dup.LastName )

acc.adderror(

'le contact existe déja(already exists');

}

}

}

if

(trigger.isupdate)

{

for

(contact acc:trigger.new)

{

for

(contact dup:listnames)

{

if

(acc.FirstName==dup.FirstName && acc.FirstName !=trigger.oldmap.get(acc.id).FirstName && acc.LastName==dup.LastName && acc.LastName !=trigger.oldmap.get(acc.id).LastName)

acc.adderror('le contact existe déja(already exists)');

}

}

}

}

}

 

 

hope that helps  (excuse my English, am french)

 

 

pjaenick.ax736pjaenick.ax736

If the user was inserting "Bob Jones", wouldn't this prevent entry if the system already contains contacts for a "Bob Smith" and "Mary Jones" ?