• Pravin Shewale
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

I tried the below trigger code but, getting  unexpected exception can anyone help.

trigger UpdateEmail on Contact (after insert, after update) {
    Set <String> AccId = New Set <String> (); 
    For (Contact con: Trigger.new){ 
        if (con.AccountId != Null ){ 
        AccId.add(con.AccountId); 
        } 
    } 
    List<Contact> con = [SELECT Id,LastName, Email, Account.Id FROM Contact WHERE Account.Id != null];
    List<Contact> newCon = new List<Contact>();
    for(Contact con: Trigger.new){
        Contact Cont = new Contact();
        Cont.Id = con.AccountId;
        Cont.Email = con.lastname+'@test.com';
        System.debug('Test'+Cont.Id);
        newCon.add(Cont);
    }
    update newCon;

}