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
Sindhu AmbarkarSindhu Ambarkar 

Getting error on executing the trigger.When the account shipping address is updated the contact should update with shipping address fields

rigger Acc_Con_Insert on Account (after update) {
    List<Account> acc = new List<Account>();
    List<Account> acc1 = new List<Account>();
    acc1 = [SELECT id, BillingAddress from Account WHERE id IN :Trigger.new];
    for(Account acc2: acc1) {
        if(acc2.BillingAddress != null)
        {
            acc.add(acc2);
        }
    }
    UpdateContact uc = new UpdateContact();
    uc.m1(acc);
}

public class UpdateContact {
public void m1(List<Account> accounts)
{
    List<Contact> con_upd=new List<Contact>();
    Map<Id,Account> m1=new Map<Id,Account>([select id,name,BillingStreet,(select id,lastname,MailingStreet from Contacts) from Account where id in:accounts]);
    for(Account acc: accounts){
        for(Contact c1:m1.get(acc.id).contacts){
            c1.MailingStreet=acc.BillingStreet;
            con_upd.add(c1);
        }
    }
    update con_upd;
}
}
Chandra Sekhar CH N VChandra Sekhar CH N V
I would suggest you go for process builder, instead of a trigger. The above logic can be acheived in a process builder.
Arunkumar RArunkumar R
Hi Sindhu,

Change your helper class like below,
 
public class UpdateContact {
public void m1(List<Account> accounts)
{
    List<Contact> con_upd=new List<Contact>();
    Map<Id,Account> m1=new Map<Id,Account>([select id,name,BillingStreet,(select id,lastname,MailingStreet from Contacts) from Account where id in:accounts]);
    for(Account acc: m1.values()){
        for(Contact c1:m1.get(acc.id).contacts){
            c1.MailingStreet=acc.BillingStreet;
            con_upd.add(c1);
        }
    }
    update con_upd;
}
}

You have given accounts instance in for loop instead map(m1).