function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bnr84bnr84 

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

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sornasorna

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

cbernalcbernal

Try using this query:

 

SELECT Name,npe5__Affiliation__r.ContactLastName FROM Account

sornasorna

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

This was selected as the best answer
jd123jd123

Try this code

 

SELECT Name, (SELECT ContactLastName FROM npe5__Affiliations__c) FROM Account

 

Example 

SELECT Amount, Id, Name,
  (
    SELECT Quantity, ListPrice,
 PricebookEntry.UnitPrice, PricebookEntry.Name 
    FROM OpportunityLineItems
  )
FROM Opportunity



SELECT Account.Name, (SELECT Contact.FirstName, Contact.LastName FROM Account.Contacts) FROM Account

 

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 

 

 

 

 

bnr84bnr84

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.