You need to sign in to do that
Don't have an account?
Sindhu 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;
}
}
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;
}
}
Change your helper class like below,
You have given accounts instance in for loop instead map(m1).