You need to sign in to do that
Don't have an account?
NewBee21
Trigger to update Contact's Last Name when Account Name is updated
I have written a Trigger in which whenever I create an Account, new Contacts are created with the Last Name same as the Account Name. But now when I try to update the Account Name, Contact's last name remains unchanged. I want it to get updated whenever I update my Account Name. How do I achieve this?
**Trigger** ==>
trigger Account1 on Account (after insert,after update) {
list <contact> con=new list <contact>();
for(Account acc : trigger.new){
contact c = new contact();
c.LastName = acc.Name;
c.AccountID = acc.ID;
con.add(c);
}
insert con;
}
**Trigger** ==>
trigger Account1 on Account (after insert,after update) {
list <contact> con=new list <contact>();
for(Account acc : trigger.new){
contact c = new contact();
c.LastName = acc.Name;
c.AccountID = acc.ID;
con.add(c);
}
insert con;
}
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Just another query,Can insert and update possible only using "after update" in above scenario and not using after insert?