You need to sign in to do that
Don't have an account?

Update the record using Map
trigger UpdateRecordMap on Update(after Update)
{
Set<Id>accid = new Set<Id>();
for(Account a : trigger.new)
{
accid.add(a.Id);
}
List<Contact>listcon = new List<Contact>();
Map<Id, Account>mapacc = new Map<Id, Account>
([Select Id, BillingCity,
(Select Id, MailingState From Contacts)
From Account Where Id In :accid]);
for(Account a : trigger.new)
{
Contact con = new Contact();
con.MailingState = a.BillingCity;
listcon.add(con);
}
if(listcon.size()>0)
{
update listcon;
}
}
Not Update the Record
{
Set<Id>accid = new Set<Id>();
for(Account a : trigger.new)
{
accid.add(a.Id);
}
List<Contact>listcon = new List<Contact>();
Map<Id, Account>mapacc = new Map<Id, Account>
([Select Id, BillingCity,
(Select Id, MailingState From Contacts)
From Account Where Id In :accid]);
for(Account a : trigger.new)
{
Contact con = new Contact();
con.MailingState = a.BillingCity;
listcon.add(con);
}
if(listcon.size()>0)
{
update listcon;
}
}
Not Update the Record
Map<Id, contact>mapcontact = new Map<Id, contact>
([Select Id, account.billingcity,mailing city from contact where accountid In :accid]);
for(contacr con: mapcontact.keyset())
{
con.MailingState = con.account.billlingcuty
listcon.add(con);
}
if(listcon.size()>0)
{
………
Invalid loop variable type expected Id was Contact
for(Account a : trigger.new)
{
accid.add(a.Id);
}
List<Contact>listcon = new List<Contact>();
Map<Id, contact>mapcontact = new Map<Id, contact>
([Select Id, account.billingcity,mailingcity from contact where accountid In :accid]);
for(contact con: mapcontact.keyset())
{
con.mailingcity = con.account.billingcity;
listcon.add(con);
}
if(listcon.size()>0)
{
update listcon;
}
Try using below code I have tested. Please make sure you have enough spaces between variables and datatypes in the code. And I hope your trigger is on Account object.
Hope this helps! Please mark as best if it does
Thanks