You need to sign in to do that
Don't have an account?
whenever contact is created or updated update email based on Contact Last Name
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;
}
Hi Pravin,
You should use Before Triggers for you Use Case. Try the Code below:
Regards,
Omar
Thanks you both..!
Issue Resolved.
regards
Omar