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
AnupamaAnupama 

How to display List<List<sobject>> on VF page.

My query returns the output as List<List<sobject>>.

When I tried to read it from VF page, it throws error

Unknown property 'VisualforceArrayList.Aircraft__c' 

 

Here is the sample code, that i have written.

 

<apex:dataTable value="{!SearchFlights}"
var="flight" styleClass="list" rendered="{!NOT(ISNULL(SearchFlights))}">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputText value="{!flight.Aircraft__c}"/>
</apex:column>
<apex:column >

 

Can anybody please explain me How to read List<List<sobject>> and display it on the on visualforce page.

XactiumBenXactiumBen

You can't display sobjects on the page since it's a base class - You have to create your own Apex Classes that is able to store all of your fields from your object.

 

Alternatively, you can just define the type of object you are using instead of SObject.

AnupamaAnupama

Thanks for the reply.

I have the query which returns data from Master-child tables.

If I define object as of type Master, i was not able to access child related fields on VF page.

 

Is there any other way to define objects?

 

MakMak

If you want to display a list of all child objects, you can use a repeat within a repeat.

 

<repeat value="OuterList" var="OuterElement"> 

  <repeat value="OuterElement.ChildRelationName" var = "child">

     <!-- Put your display code here--> 

  </repeat> 

</repeat> 

AnupamaAnupama
Thanks for the answer, but it did not work for me. Is there anything else that needs to be taken care.
puneet28puneet28

//Controller

 

List<List<SObject>> searchList = [FIND :e IN EMAIL FIELDS RETURNING
Contact (Id, Name, Email)];
contacts = (List<Contact>)searchList[0];

 

//Page

<apex:pageBlock title="Matching Contacts" rendered="{!email != null}">
<apex:pageBlockTable value="{!contacts}" var="contact" id="contactTable">
<apex:column >
<apex:facet name="header"><b>Name</b></apex:facet>
<apex:outputLink value="../{!contact.Id}">{!contact.Name}</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header"><b>Email</b></apex:facet>
{!contact.email}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

 

 

Hope this helps :)