function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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
RKSalesforceRKSalesforce
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>();
    if(trigger.isupdate){
        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);
        clist.add(c);
    }
    }
    if(Clist.size() > 0)
        update clist;
}

Please let me know if it is  helpful.

Regards,
Ramakant