You need to sign in to do that
Don't have an account?
Vikram Singh 157
I am trying to retrive records from parent to child relationship but it will dispaly error when i am using API name of contact in subquery as "Contact" but when i am using "Contacts" code will run why ?
Account a = [ Select Name,(Select FirstName,LastName from Contact) From Account where id = '0017F000007tWcL'];
Just adding on the above answer.
Please refer this (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using) link to better undersand SOQL queries.
Sandeep
All Answers
You are getting this error because while querying the child records you have Query from Child Relationship Name which can be easily found on the workbench.
The correct query will be
Account a = [ Select Name,(Select FirstName,LastName from Contacts) From Account where id = '0017F000007tWcL'];
This 'Contacts' relationshipname was retrieved from workbench as shown in the screenshot below.
Kindly keep this in mind while querying child objects in the future.
Hope this helps,
Sandeep
In Inner query you need to use Child Relationship Name not the object API name.
Thanks
Shweta
Just adding on the above answer.
Please refer this (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_using.htm#sforce_api_calls_soql_relationships_query_using) link to better undersand SOQL queries.
Sandeep