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
intern2424intern2424 

Help Navigating Soql query in visualforce

Hi, I created a parent to child query that will relate son to father but I can not get the Name, Age__c from the Father__r. I am trying to return results in my visualforce page using outputfield. Could any one help.

 

 

  


        son = [select Id, First_Name__c, Last_Name__c, Age__c, 
               (Select Id, Name, Age__c From Fathers__r) 
               from Son__c
               where name=:ApexPages.currentPage().getParameters().get('id')];


 

 

 

  <apex:outputField value="{}"/>  

  <apex:outputField value="{}"/>

 

 

 

 

 

Cool_DevloperCool_Devloper

 <apex:smileysurprised:utputField value="{!son.Fathers__r.Name}"/> 

 

Assuming that the relationship name is correct!

Cool_D

intern2424intern2424

When I try to put that in I get this error:

 

Error: Could not resolve the entity from <apex:outputField> value binding '{!Son__c.Fathers__r.Name}'. outputField can only be used with SObject fields.

 

WesNolte__cWesNolte__c

Hey

 

Your current query is child to parent btw i.e. sons are children of parents, and your 'main' query object is son. Therefore your query should be:

 

 

son = [select Id, First_Name__c, Last_Name__c, Age__c, 
               Fathers__r.Id, Fathers__r.Name, Fathers__r.Age__c
               from Son__c
               where name=:ApexPages.currentPage().getParameters().get('id')];



Your page could then output the father's details like so:

 

<apex:outputText value="{!son.fathers__r.name} />

 

Wes