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
sfrerssfrers 

Reference nested values in controller query on VF page

I am having difficulty referencing the values of my controller query in a VF page.  The scenario is looking up two different single child records from a single parent record.  When I run the SELECT query below by itself in the AJAX debug shell it returns the correct results.  However, when I attempt to reference in the VF page I see no results.  The APEX and VF syntax are both new to me.  I am stumped, any assistance is very much appreciated.

 

APEX:

 

public with sharing class VisitCtlr
{
	public gii__Product2Add__c giiPR;
	
	public VisitCtlr()
	{
		giiPR = [select Name, (select Name from Accounts__r where id='001A000000Jpj5QIAR'), (select gii__KitProduct__r.Name from gii__KitProductReference__r where gii__ProductReference__c='a0XA0000000oviFMAQ' and gii__Required__c=True) from gii__Product2Add__c where id='a0XA0000000oviFMAQ'];
	}
	
	public gii__Product2Add__c getgiiPR()
	{
		return giiPR;
	}
}

 

 

VF:

 

<apex:page controller="VisitCtlr">
  <apex:pageBlock >
    <apex:pageblocktable value="{!giiPR}" var="pr">
      <apex:pageblocktable value="{!pr.Accounts__r}" var="ac">
        <apex:pageblocktable value="{!pr.gii__KitProductReference__r}" var="kp">
           <apex:column headerValue="Kit Name">
              <apex:outputText value="{!pr.Name}"/>
           </apex:column>
           <apex:column headerValue="Account Name">
              <apex:outputText value="{!ac.Name}"/>
           </apex:column>
           <apex:column headerValue="Product">
              <apex:outputText value="{!kp.Name}"/>
           </apex:column>
        </apex:pageblocktable>
      </apex:pageblocktable>
    </apex:pageblocktable>
  </apex:pageBlock>
</apex:page>

 

 

All the best,

Steven

_Prasu__Prasu_

Declare variable "giiPR" as a array or List and that code should work.

sfrerssfrers

Thanks for the assistance, Prasanna.  Here is my update, but I receive the same result.  I feel like I am missing something obvious but haven't figured it out.

 

Controller:

 

 

public with sharing class VisitCtlr
{
	public List<gii__Product2Add__c> getgiiPR()
	{
		List<gii__Product2Add__c> giiPR = 
				[select Name, (select Name from Accounts__r where id='001A000000Jpj5QIAR'),
				 (select gii__KitProduct__r.Name from gii__KitProductReference__r 
				 where gii__ProductReference__c='a0XA0000000oviFMAQ' 
				 and gii__Required__c=True) from gii__Product2Add__c 
				 where id='a0XA0000000oviFMAQ'];
		return giiPR;
	}
}

 

 

VF page: (same)

 

<apex:page controller="VisitCtlr">
  <apex:pageBlock >
    <apex:pageblocktable value="{!giiPR}" var="pr">
      <apex:pageblocktable value="{!pr.Accounts__r}" var="ac">
        <apex:pageblocktable value="{!pr.gii__KitProductReference__r}" var="kp">
           <apex:column headerValue="Kit Name">
              <apex:outputText value="{!pr.Name}"/>
           </apex:column>
           <apex:column headerValue="Account Name">
              <apex:outputText value="{!ac.Name}"/>
           </apex:column>
           <apex:column headerValue="Product">
              <apex:outputText value="{!kp.Name}"/>
           </apex:column>
        </apex:pageblocktable>
      </apex:pageblocktable>
    </apex:pageblocktable>
  </apex:pageBlock>
</apex:page>

 

 

Regards,

Steven