• charu tekade
  • NEWBIE
  • 0 Points
  • Member since 2019

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

I have account stage name fields ( name is new, open, losedwon,
losedlost) in opportunity object have stage name (new, open, losedwon, losedlost) i have account have abc , but opportunity have records have 10 records (2 is new, 2 is open, losedwon is 3, losedlost is 4) you display total as well in account object and individual records also display using trigger how

Thanks in Advance
Charan
trigger PreventDuplicateOnContact on Contact (before insert) {
    // Set to store Phone No's
    Set<String> ContactPhoneSet = new Set<String> ();
    // Set to store Email ID's
    Set<String> ContactEmailSet = new Set<String> ();
    
    // Iterate through each new Contact and add their email and Phone in to Sets 
    for(Contact Con : Trigger.new) {
        ContactPhoneSet.add(con.Phone);
        ContactPhoneSet.add(con.Email);
    }
   
   List<Contact> ContactPhoneList = new List<Contact>();
   List<Contact> ContactEmailList = new List<Contact>();
    
    
   ContactEmailList = [Select email From Contact Where Email IN : ContactEmailSet];
   ContactPhoneList = [Select Phone From Contact Where Phone IN : ContactPhoneSet];
   
   for(Contact Con : Trigger.new) {
       If(ContactEmailList.size() > 0) {
           Con.Email.AddError('Duplicate Contact Found With Same Email');
           System.debug('Email'); 
         }
        
       If(ContactPhoneList.size() > 0) {
          Con.Phone.AddError('Duplicate Contact Found With Same Phone');
        }
  }  
    
}
  • October 08, 2020
  • Like
  • 0