I have a question in regards to Nested SOQL queries and exposing their fields, that are part of that Nested SOQL, into a Visualforce page.
This is a structure sample:
List<Object1> obLis=[SELECT Id, Name,
(SELECT Id, Name FROM Object 2), (SELECT ID, Name FROM Object3 FROM Object1 LIMIT 500];
The Object one has a Parent relationship over Object 2 and Object 3.
What I want is to be able to retrieve the fields on that query and expose them in a Visualforce keeping the relation between objects.
Lest's say we have this example from SFDC:
//Controller
public with sharing class TestDisplayQueryList{
public List<Account> Records {get; set;}
public TestDisplayQueryList(){
Records = [select Name, AccountNumber, CleanStatus from
Account where CleanStatus='Pending'];
}
}
This can be uses in Visualforce like this to expose the fields:
<apex:page controller="TestDisplayQueryList">
<apex:pageBlock title="My Content">
<apex:pageBlockTable value="{!Records}" var="Record">
<apex:column >
<apex:facet name="header">Account Name</apex:facet>
<apex:outputText value="{!Record.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Account Number</apex:facet>
<apex:outputText value="{!Record.AccountNumber}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Clean Status</apex:facet>
<apex:outputText value="{!Record.CleanStatus}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
This is very clear and straight forward. But, how can I get the fields from Object 2 and Object 3 in the nested SOQL query to show up in the Visualforce?:
List<Object1> obLis=[SELECT Id, Name,
(SELECT Id, Name FROM Object 2), (SELECT ID, Name FROM Object3 FROM Object1 LIMIT 500];
The all idea is that I want to be able to expose in a table all the records related in Objects 1, 2 and 3
Thanks.
This is the controller I'm using:
public class OrderQuery
{
public List<Account> acclist {get; set;}
public OrderQuery()
{
acclist= [SELECT Name, KvK_nummer__c, Street_Name__c, House_Number__c, House_Number_Suffix__c, Zip_code__c,RecordTypeId,
(SELECT OrderNumber, Status,Type, BillToContactName__c, EffectiveDate FROM Orders WHERE Status='Confirmed'),
(SELECT FirstName, LastName, Title, MobilePhone, Email FROM Contacts) FROM Account LIMIT 20];
}
}
The page:
<apex:page controller="OrderQuery" sidebar="false">
<apex:pageBlock title="Orders Block">
<apex:pageBlockTable value="{!accList}" var="acct">
<apex:column value="{!acct.Name}"/>
<apex:repeat value="{!acct.Orders}" var="obj2">
<apex:column value="{!obj2.OrderNumber}"/>
</apex:repeat> </apex:pageBlockTable> </apex:pageBlock></apex:page>