+ Start a Discussion
Shruti VishShruti Vish 

how to update child record based on parent field

I have one senario where i have on account i want to display related contacts and have one custom field email on account the same email should be reflected to related contacts.for this i need to write pseudo code or apex class
Hi Shraha,

Please find below teigger:
trigger AccountAddressTrigger on Account (before update) {
    List<Contact> clist = new List<Contact>();
    Map<String, String> emailMap = New Map<String, String>();
        for(Account a: Trigger.new)
        if(trigger.oldmap.get(a.id).Fax != trigger.Newmap.get(a.id).Fax){
            emailMap.put(a.id, a.Fax);
    for(Contact c : [Select id, Fax, accountid from Contact where Accountid in : emailMap.keyset()])
        c.fax = emailMap.get(c.accountid);
    if(Clist.size() > 0)
        update clist;

Please let me know if it is  helpful.