You need to sign in to do that
Don't have an account?

Creating a pop up displaying Contact details
Hi,
I have written a trigger to catch duplicates in Contacts.
In tha last step i wish to show the Contact( for whom the duplicate is caught) details that already exists in the system.
Thank You
I think what you are looking to show a duplicate match inline to a contact if there is any
Please explain
1. What is your duplicate criteria only Name or Name + Email or nay other
2. What is the action trigger does once duplicate is found
When the duplicate is caught , it is throwing an error. I am looking if the error is displayed along with the existing Contact details on a separate page.
Here's the trigger:
trigger Duplicate1 on Contact (before insert) {
set<Id> accIds = new set<Id>();
for(Contact p :trigger.new){
accIds.add(p.accountId);
}
map<Id,account> parentAccmap = new map<Id,account>([select Id,parentId,recordtypeId from account where Id IN :accIds and parentId!=NULL and recordtypeId='012600000005J5J']); //add Site record type Id here.
set<ID> parentIds = new set<ID>();
for(Account acc : parentAccmap.values()){
parentIds.add(acc.parentId);
}
map<Id,Set<String>> parentPrMap = new map<Id,Set<String>>();
list<Contact> prParentlist = [select ID,Email,Name,AccountId, Account.recordtypeId,Phone,FirstName, lastName from Contact where AccountId IN:parentIDs and Account.recordtypeId='012600000005J5I']; //add Customer record type Id here.
for(Contact pr:prParentlist){
if(parentPrMap.get(pr.AccountId) == null){
parentPrMap.put(pr.AccountId, new Set<String>());
}
parentPrMap.get(pr.AccountId).add(pr.email);
parentPrMap.get(pr.AccountId).add(pr.phone);
parentPrMap.get(pr.AccountId).add(pr.firstname);
parentPrMap.get(pr.AccountId).add(pr.lastname);
}
list<Contact> prParentlist2 = [select ID,Email,Name,account.parentid, Account.recordtypeId,Phone,FirstName, lastName from Contact where account.parentid in :parentIDs and Account.recordtypeId='012600000005J5J']; //add Customer record type Id here.
for(Contact pr:prParentlist2){
if(parentPrMap.get(pr.account.parentid) == null){
parentPrMap.put(pr.account.parentid, new Set<String>());
}
parentPrMap.get(pr.account.parentid).add(pr.email);
}
system.debug(parentPrMap);
for(Contact prr:trigger.new){
if(
prr.email!=null
&& parentAccmap.containsKey(prr.Accountid)
&& parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)
){
if((parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.email))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.phone))&&(parentPrMap.get(parentAccmap.get(prr.Accountid).ParentId).contains(prr.lastname))){
String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ prr.accountid +'"> Please Create a Contact Role </a>';
prr.addError('This Contact already exists.'+ errorMsg,false);
}
}
}
}
Although your duplicate finding logic could easly be reduced
1. Create a Text ( 255 ) Unique Field on contact
2. Develop a trigger or workflow to populate it with all field contributing in duplicate
contact.Name + contact.Email + Contact.Phone
By this when another contact will be created you will see errro message with URL to existing contact.
contact.AccountId + contact.Name + contact.Email + Contact.Phone
to make it account specific .