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

Displaying a list of duplicates


I have written a trigger to catch duplicate Contacts. How is it possible to display the details of the already existing contact , whenever a duplicate is caught.
Also i need to display 2 buttons there, One would allow creating the duplicate contact and the other would take the user to Create Coontact Role page.
Any help is appreciated.
Thank You.
following is the trigger to catch duplicate:

trigger Duplicate1 on Contact (before insert) {
    set<Id> accIds = new set<Id>();

    for(Contact p{
    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()){
    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>());

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>());
            && parentAccmap.containsKey(prr.Accountid)
            && parentPrMap.containsKey(parentAccmap.get(prr.Accountid).ParentId)
                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);