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
Newbie__SalesforceNewbie__Salesforce 

How to display data of two inner query in apex:pageBlockTable

My query is
List<Order> lstOrder = [SELECT Id,(SELECT Id FROM Attachments),(SELECT Id,PricebookEntry.Product2.Name FROM OrderItems) FROM Order WHERE Id IN :lstId];

I have tried to display using repeat
<apex:pageBlock >
				<apex:repeat value="{!lstOrder}" var="myFeedVar" >
					<tr>
						<td>
							<apex:repeat value="{!myFeedVar.Attachments}" var="item" >
					       		<apex:image value="/servlet/servlet.FileDownload?file={!item}" id="someImage" height="500px" width="500px"/>  
					    	</apex:repeat>
					   	</td>
					   	<td>
					   		<apex:repeat value="{!myFeedVar.OrderItems}" var="item" >
					       		<apex:outputField value="{!item.Product2.Name}">
					    	</apex:repeat>
					   	</td>
				       	<td>
				       		<apex:commandButton value="LIKE"/>
				       	</td>
				   </tr>
				    
				    <br/><br/>
				</apex:repeat>	
	       	</apex:pageBlock>

I am unable to display OrderItems in repeat. 
Best Answer chosen by Newbie__Salesforce
jigarshahjigarshah
You can use the code below which uses a pageBlockTable and nested dataTables to display the Attachments and Order Items related to an Order record.

Apex Controller Code
public with sharing class OrderController{

	public List<Order> orderList {get; set;}
	
    //Retrieve and store Orders along with associated Attachments and Order Items
	public void displayOrders(){
		orderList = [SELECT Id, Name
						(SELECT Id FROM Attachments),
						(SELECT Id, Name, PricebookEntry.Product2.Name FROM OrderItems) 
					 FROM Order 
					 WHERE Id IN :lstId];
	}
}

Visualforce Code
<apex:page controller="OrderController" action="{!displayOrders}">

    <apex:pageBlock title="Order Details">

		<apex:pageBlockTable value="{!orderList}" var="ord">
            
			<apex:column value="{!ord.Name}" headerValue="Order"/>
			
			<!-- Display the associated Attachments -->
            <apex:column breakBefore="true">
							
				<apex:dataTable value="{!ord.Attachments}" var="att" >
				
					<apex:column headerValue="Attachments">
						<apex:image value="/servlet/servlet.FileDownload?file={!att.Id}" height="500px" width="500px"/> 
					</apex:column>
				</apex:dataTable>
            </apex:column>
			
			<!-- Display the associated Order Items -->
			<apex:column breakBefore="true">

				<apex:dataTable value="{!ord.OrderItems}" var="item" >
				
					<apex:column value="{!item.Name}" headerValue="Order Item Name"/>
					<apex:column value="{!item.PricebookEntry.Product2.Name}" headerValue="Product"/>
					
				</apex:dataTable>
            </apex:column>
			
        </apex:pageBlockTable>
    </apex:pageBlock>
	
</apex:page>
This should help you display the retrieved information on a Visualforce page.