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;
}