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 

Need help with Navigating my soql query

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="{}"/>

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Cool_DevloperCool_Devloper

Ok, so in your case, when you run the query, you get son and the related father objects.Right?

The exception that you are getting means, that the VF component is expecting a list of related records. So, basically, you have to loop through "{!son__c.fathers__r}" list in your VF page!

Something like-

<apex:repeat value="{!son__c.fathers__r}" var="temp">

{!temp}

</apex:repeat>

Cool_D

All Answers

Cool_DevloperCool_Devloper

Already answered on VF discussion board!

Cool_D

intern2424intern2424

I keep on getting this error 

 

Error: Unknown property 'VisualforceArrayList.Name'

intern2424intern2424

This is what my class looks like: 

 

public class sonExtension {
    
    Son__c[]  son;
    

    public sonExtension(ApexPages.StandardController controller) 
    
    {

        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')];

    }

}

 

 

This is what my Visualforce page looks like:

 

<apex:page standardController="Son__c" extensions="sonExtension">    <apex:form ><apex:sectionHeader title="View Son"/>        <apex:pageBlock >           <apex:pageBlockButtons >              <apex:commandButton value="Edit" action="{!edit}"/>              <apex:commandButton value="Delete" action="{!delete}"/>                                </apex:pageBlockButtons>                                    <apex:pageBlock title="View Person" id="thePageBlock" mode="view">               <apex:pageBlockSection title="Person Information" columns="1"/>                                   <apex:actionRegion >                       <apex:pageBlockSection columns="2">                                                                         <apex:outputField value="{!Son__c.Name}"/>                             <apex:outputField value="{!Son__c.Age__c}"/>                                                       <apex:outputField value="{!Son__c.Father_of_Son__c}"/>                            <apex:outputField value="{!Son__c.First_Name__c}"/>                           <apex:outputField value="{!Son__c.Last_Name__c}"/>                                                                </apex:pageBlockSection>                                                                                                                                         </apex:actionRegion></apex:pageBlock><apex:pageBlock title="View Father" id="FatherPageBlock" mode="view">               <apex:pageBlockSection title="Father Information" columns="1"/>                                   <apex:actionRegion >                       <apex:pageBlockSection columns="2">                                                                                            //This is where I am trying to call the Father information                                                                                                                                     </apex:pageBlockSection>                                                                                                                                         </apex:actionRegion></apex:pageBlock>            </apex:pageBlock></apex:form><apex:relatedList list="Fathers__r" /></apex:page>

 

Message Edited by intern2424 on 11-24-2009 07:47 AM
Cool_DevloperCool_Devloper

Try the below code-

public class sonExtension {
    
    Son__c[]  son;
    

    public sonExtension(ApexPages.StandardController controller) 
    
    {

        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')];

    }

}

 

I am assuming that Father__c is the Parent and Son__c is the child here!! Also, make sure that the relationship name is "Fathers__r" from son__c to father__c object.

Cool_D

intern2424intern2424
No the master object is Son__c and the parent is the child object.
intern2424intern2424

Son__c object has 5 fields : Age__c (Number), Father(Lookup),  First_Name__c(text), Last_Name__c(text), Name (Text).

 

Details within Father Lookup 

 

Field LabelFatherObject NameSon
Field NameFather_of_SonData TypeLookup
API NameFather_of_Son__c  

 

 

Related ToFatherChild Relationship NameSons
  Related List LabelSons

 

 

 

Father__c object has Name,  Age__c (Number), Son(Lookup)

 

Details within Son Lookup  

 

Field LabelSonObject NameFather
Field NameSonData TypeLookup
API NameSon__c

 

 

Related ToSonChild Relationship NameFathers
  Related List LabelFathers (Son)

 

 

 

Cool_DevloperCool_Devloper

Ok, so in your case, when you run the query, you get son and the related father objects.Right?

The exception that you are getting means, that the VF component is expecting a list of related records. So, basically, you have to loop through "{!son__c.fathers__r}" list in your VF page!

Something like-

<apex:repeat value="{!son__c.fathers__r}" var="temp">

{!temp}

</apex:repeat>

Cool_D

This was selected as the best answer
intern2424intern2424

Man, Thank you soooooooo much. I was wondering with the repeat can you still do outputfield? 

 

Thank you again for all the help.