0

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

  • Without understanding the object model, I'd suggest you build your queries via the developer workbench, which may help you through this quickly. – CloudHugger Feb 9 '15 at 6:25
  • In your second example, try using a lower-case 'c' for 'Attendee__c'. In your third example, since the Attendee__c is a custom object, all its relationships will be custom as well, so it can't be straight 'Account.Name'. Maybe 'Account__r.Name', but look at the lookup field definition on the object to be sure. Similarly for your 'Festivals__r' lookup issue from the first example. While Salesforce will suggest a relationship name, it can be overridden during the creation of the relationship field. – Thomas Taylor Feb 9 '15 at 6:48
  • How can I lookup field definition on object like you suggest for a child to parent relationship? For parent to child I could locate the child relationship field name (typically plural_r)? – Think First Feb 16 '15 at 0:14
1

Your queries look correct (at least the format of them) at first glance......

To get the correct relationship name for the Parent to Child Query navigate to:

Setup -> Develop -> Custom Object

  1. Click on the object Name for the CHILD object
  2. Find the Master Relationship Field and click on it
  3. Look at the Child Relationship Name

ex.

enter image description here

In this case the query from Parent to Child would be:

Select ID, (Select ID From GetFeedback_Survey_Answers__r) From GetFeedback_Survey_Result__c

For a query from Child to Parent you would simply uses the Name of the Master Relationship Field....

In the above case, using the same steps 1-2 but looking at API Name

enter image description here

The query would be

Select ID, GetFeedback_Survey_Result__r.Name From GetFeedback_Survey_Answer__c

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.