• Steve Robbins
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
Is there a need for a team of Salesforce contractors with experience in every aspect of Salesforce with clients from start up to multi-billion dollar, multi-national corporation including Architect, Business Analyst, Sr. Developer, Scrum Master, and QA developer as well as program/project manager?

Hi,

the following trigger was designed to prevent duplicate contacts on an account. But even when i edit the same contact and click save, the trigger acts and does not let me save the contact.

please help me figure out whats wrong with the trigger

trigger PreventDuplicateContact on Contact (after insert,after update) {
   
    if(trigger.isInsert || trigger.isUpdate)
    {
        Map<Id,List<Contact>> accMap = new Map<Id,List<Contact>>();
        List<Contact> contactList;
       
        for(Contact c: [Select Id,Email,accountId from Contact]){
            if(accMap.containsKey(c.accountId)){  
                accMap.get(c.accountId).add(c);
            }
            else{
                contactList = new List<Contact>();
                contactList.add(c);
                accMap.put(c.accountId,contactList);
            }      
        }
       
        for (Contact c : Trigger.new)
        {
            if(accMap.containsKey(c.accountId)){
                for(Contact con : accMap.get(c.accountId)){
                    if(c.Email == con.Email){
                       // c.Email.addError('Contact with this email address already exists.Please create a Contact Role. <a href=https://cs18.salesforce.com/02Z/e?parentId='+c.accountid+'\'>Create a Contact Role</a>',false);
                       String baseUrl = URL.getSalesforceBaseUrl().toExternalForm()+'/02Z/e?parentId=';
string errorMsg = '<a style=\'color:1B2BE8\'href="'+baseUrl+ c.accountid +'"> Create a Contact Role  </a>';

c.Email.addError('Contact with this email address already exists.Please create a Contact Role'+ errorMsg,false);
                    }
                }
            }
        }
    }
}

  • September 26, 2014
  • Like
  • 0
Hi Folks,

Can someone help me,

Am not able to see the line-by-line code coverage in Developer Console, though am able to see the percentage covered.

Is it a known issue or am doing something wrong.

Please suggest.

Many Thanks,
Uday
  • September 26, 2014
  • Like
  • 0