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

Parent to Child Query Problems
Hello,
I am trying to create a simple query involving the account object, and a custom object. But the query causes an error of
"INVALID_TYPE - Didn't understand relationship"
The affiliation object is a child relative to Account and both values are strings so I am not sure what the issue is. The query is below.
SELECT Name, (SELECT ContactLastName FROM npe5__Affiliation__c) FROM Account
Each relationship will have a relationship name...you have to use that in the query...you find the relationship name in eclipse (open the schema in eclipse -> go to the account lookup field in npe5_Affiliation__c object -> there will a child relationship name)...or you can find it in salesforce UI if you open that field...so your query should be like this:
SELECT Name, (SELECT ContactLastName FROM childrealtionshipname) FROM Account
All Answers
Try using this query:
SELECT Name,npe5__Affiliation__r.ContactLastName FROM Account
Each relationship will have a relationship name...you have to use that in the query...you find the relationship name in eclipse (open the schema in eclipse -> go to the account lookup field in npe5_Affiliation__c object -> there will a child relationship name)...or you can find it in salesforce UI if you open that field...so your query should be like this:
SELECT Name, (SELECT ContactLastName FROM childrealtionshipname) FROM Account
Try this code
SELECT Name, (SELECT ContactLastName FROM npe5__Affiliations__c) FROM Account
Example
for more understand please see this
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_relationships.htm
if it is right solution please mark it as accept as a solution other wise please let me know
Thanks cbernal, but that query still causes the same error "didnt understand relationship"
sorna and jd123, thank you as well. Both queries work and include useful information for finding the issue in the future. I am not sure if I can mark both as solutions, but I will try. Thanks again.