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
                                ];    
  • 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 '16 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 '16 at 13:06
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.

| improve this answer | |
  • 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 '16 at 12:31
  • @ApexN-u-b I think you should read this article: Understanding Relationship Names – Sergej Utko Apr 6 '16 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 '16 at 12:57

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.