You need to sign in to do that
Don't have an account?
Updating contacts from account
Hi,
I am trying to update contact's phone by querying the account , But it gives me following error
"A non foreign key field cannot be referenced in a path expression: Contacts"
try
{
Account a=[select name,(select name from contacts ) from account];
a.name='Dialog';
a.contacts.phone=123;
update a;
update a.Contacts;
}
catch(DmlException e)
{
System.debug(e.getMessage());
}
I am trying to update contact's phone by querying the account , But it gives me following error
"A non foreign key field cannot be referenced in a path expression: Contacts"
try
{
Account a=[select name,(select name from contacts ) from account];
a.name='Dialog';
a.contacts.phone=123;
update a;
update a.Contacts;
}
catch(DmlException e)
{
System.debug(e.getMessage());
}
You are getting error because ac.contacts will return the list of contact and you are trying to access .phone from list<Contact>. To access the phone field you have iterate the returned contact list , below is the updated trigger for you:
Marked Solved if it does help you.
All Answers
You are getting error because ac.contacts will return the list of contact and you are trying to access .phone from list<Contact>. To access the phone field you have iterate the returned contact list , below is the updated trigger for you:
Marked Solved if it does help you.