0

Below is my current query. I Program is a master to Application object. Application is also a details to the Contact object. How can I modify my query to get the first name of the contact?

[Select Name,Seminar1__r.Name,Seminar2__r.Name,Seminar3__r.Name,Seminar4__r.Name,Seminar5__r.Name,Seminar6__r.Name,Seminar7__r.Name,Seminar8__r.Name,Seminar9__r.Name,Seminar10__r.Name,Seminar11__r.Name
                                From Program__c
                                Where ID = :programID
                                ];    
2
  • For clairty, using the following notation Parent => Child, your objects look like Program__c => Application__c and Contact => Application__c, correct?
    – Derek F
    Apr 6, 2016 at 11:59
  • The result of this query may have more contacts right? Program can have more than one applciations and each application aligned with its parent Contact?
    – Maha
    Apr 6, 2016 at 13:06

1 Answer 1

2

If I understand your question and database structure right, then you should be able to get all the "Application" children of the "Program" master using a subquery (child relationship):

Select Name, Seminar1__r.Name, (Select Contact__r.FirstName From Applications__r)
From Program__c
Where ID = :programID

Where "Applications" is a name of the child relationship to the "Application" from the "Program" master, and "Contact__r.FirstName" is a lookup to the Contact object from the "Application" object.

3
  • I added the (Select Contact__r.FirstName From Applications__r) but it didn't like it. Just to be clear, I need to go down a level and then up. Not a stand traversing scenario of just up a few levels or down. Is this clearer?
    – Apex N-u-b
    Apr 6, 2016 at 12:31
  • @ApexN-u-b I think you should read this article: Understanding Relationship Names Apr 6, 2016 at 12:35
  • I read it but it doesn't tell me how to go down and then up like (SELECT Onward_Israel_Program__r.Onward_Application__r.Contact__r.FirstName FROM Contact__r) which does not work but something like I need to do.
    – Apex N-u-b
    Apr 6, 2016 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .