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
magandrezmagandrez 

How can I show fields from a child relationship

Hi all,

 

I have this SOQL with a child relationship (parent-to-child)

 

[SELECT Name, Birthdate, (SELECT Name_Em__c, Job_Title__c FROM Employment__r),
 (SELECT Degree__c, Name_Ed__c FROM Education__r)
FROM Contact WHERE Id IN (SELECT Candidate_Contact__c
      FROM Application__c

      WHERE Job__c =:JobOrderId)

];

 

And the following Visualforce on a pageblocktable:

 

<apex:column headerValue="Company" value="{!ed.Employment__r.Name_Em__c}"/>

 

But I cannot get the information from the two sub-select into the table. 

 

Do you have any idea on how to get it?

 

Many thanks,

 

MGA.

Nilesh ManeNilesh Mane

Try this........

 

 

[SELECT Name, Birthdate, (SELECT Name_Em__c, Job_Title__c FROM Employments__r),
 (SELECT Degree__c, Name_Ed__c FROM Educations__r)
FROM Contact WHERE Id IN (SELECT Candidate_Contact__c
      FROM Application__c

      WHERE Job__c =:JobOrderId)

];

 

magandrezmagandrez

Hi,

 

I already tried and it didn't work...

 

 

Sam27Sam27

I guess you jst can't fetch the child data from parent by using dot(.) notation........the dot notations works from child to parent and not vice versa (for ex. - Contact.Account.id is fine but not Account.Contact.id)........

 

why?? since a parent can have multiple child and if you use dot notation ideally it dont know which child object data to show even in query you are fetching only one child data.

 

So the solution I guess is to use a wrapper class  and get the list of Education__c and Employment__c by .getSObjects('Education__r') and .getSObjects('Employment__r') and then parse it to get the one child and then put it in wrapper class corresponding to the contact.

 

Then on page you would be able to fetch it. tedious?? yes it is a bit.