You need to sign in to do that
Don't have an account?
Forcedotcom737
Help with simple SOQL relationship queries that wont work?
Trying to understand relationship queries. Could you please review the quesries that wont work below and comment on what I am doing incorrectly?
I have 2 objects:
Festivals__c (Parent Object to Attendee)
Attendee object has two lookup fields Account & Festivals (name of festival)
These wont work
(Trying to query Attendee Name, Tickets purchased and Festival Name (Master-Detail); going from child to parent)
SELECT Name,Tickets_Purchased__c,Festivals__r.Name FROM Attendee__c
(Trying to Query festival Name and attendee name - going from parent to child)
SELECT Festivals__c.Name, (SELECT Name FROM Attendee__C) FROM Festivals__c
(Trying to Query Attendee Name, tickets purchased and lookup Account)
SELECT Name,Tickets_Purchased__c,Account.Name FROM Attendee__c
These statements work:
SELECT First_Name__c,Tickets_Purchased__c FROM Attendee__c
SELECT Festivals__c.Name FROM Festivals__c
SELECT Name FROM Attendee__C
Sample Error Messages:
Didn't understand relationship 'Festivals__r' in field path.
Didn't understand relationship 'Attendee__C'
Didn't understand relationship 'Account' in field path
I have 2 objects:
Festivals__c (Parent Object to Attendee)
Attendee object has two lookup fields Account & Festivals (name of festival)
These wont work
(Trying to query Attendee Name, Tickets purchased and Festival Name (Master-Detail); going from child to parent)
SELECT Name,Tickets_Purchased__c,Festivals__r.Name FROM Attendee__c
(Trying to Query festival Name and attendee name - going from parent to child)
SELECT Festivals__c.Name, (SELECT Name FROM Attendee__C) FROM Festivals__c
(Trying to Query Attendee Name, tickets purchased and lookup Account)
SELECT Name,Tickets_Purchased__c,Account.Name FROM Attendee__c
These statements work:
SELECT First_Name__c,Tickets_Purchased__c FROM Attendee__c
SELECT Festivals__c.Name FROM Festivals__c
SELECT Name FROM Attendee__C
Sample Error Messages:
Didn't understand relationship 'Festivals__r' in field path.
Didn't understand relationship 'Attendee__C'
Didn't understand relationship 'Account' in field path
Secondly, your queries look ok for the most part, but you just need to pay attention to the differences between the API name of the lookup field, versus the Child Relationship API name (Used by subqueries looking from the parent down to the child, you can find the Child Relationship API name on the lookup or master detail field on the child object).
Without knowing the exact API names in your org, here's what the three queries *should* be:
All Answers
Secondly, your queries look ok for the most part, but you just need to pay attention to the differences between the API name of the lookup field, versus the Child Relationship API name (Used by subqueries looking from the parent down to the child, you can find the Child Relationship API name on the lookup or master detail field on the child object).
Without knowing the exact API names in your org, here's what the three queries *should* be:
The parent to child queries are clear to me where you use the 'plural version'. I was able to locate this in the child relationship name field when viewing the custom lookup / master detail relationship field.
I am not clear on the child to parent query where you use the singular version (Festival__r). Where can I find the singular name / relationship name that needs to be used for child to parent type scenarios? The object name is Festivals. Could you please explain how this works?