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
ECoronaECorona 

Display columns from subquery on VF Page

Hi ! I have this query
 
SELECT Id, Name, (SELECT Proveedores__c FROM Proveedores__r), (select name from opportunities where createddate =this_year and stagename='Ganada') FROM Account 
where id in (SELECT Cuenta__c FROM Proveedores__c)
and id in (select accountid from opportunity where createddate =this_year and stagename='Ganada')    

But now i'm stuck in how i can show all the Account Name, the Proveedores__c columns and the Opportunity name in a visualforce page

I'll really appreciate your help!!!
 
Vivek DVivek D
You can do something like this if you are using standard VF page
<apex:pageBlockTable value="{!ListOfAccount}" var="acc">
	<!- Account Name -->
	<apex:column value="{!acc.Name}" headerValue="Account Name"/>
	<!- Related Object Details -->
	<apex:column>
		<apex:pageBlockTable value="{!acc.Proveedores__r}" var="pro">
		<apex:column value="{!pro.someField}" headerValue="Some Field of related Object"/>
		</apex:pageBlockTable>
	</apex:column>
	<!-- Opp Details -->
	<apex:column>
		<apex:pageBlockTable value="{!acc.opportunities}" var="opp">
		<apex:column value="{!opp.Name}" headerValue="Opp Name"/>
		</apex:pageBlockTable>
	</apex:column>
</apex:pageBlockTable>

It will display related object details per account name.

If you are using HTML or non VF tags you can use apex:repeat in same manner
Nayana KNayana K
Suppose you have stored accounts in lstAccount variable then in VF you can do like this :

<apex:pageBlock id="pb"> 
	<apex:repeat value="{!lstAccount}" var="objAcc">
		<table border="1" width="95%">
		<tr>
			<td>
				<h5>{!objAcc.Name}</h5>
			</td>
		</tr>
		<tr>
			<td>
				Proveedores <br/>
				<table border="1" style="margin-left:10px;" width="90%">
					 <apex:repeat value="{!objAcc.Proveedores__r}" var="objProv" rendered="{!objAcc.Proveedores__r.size > 0}">
						<tr>
							<td><apex:outputField value="{!objProv.Proveedores__c}"/></td>
						</tr>
					</apex:repeat>
					<tr style="display:{!IF(objAcc.Proveedores__r.size == 0,'block','none')}">
						<td><h1>No Proveedores</h1></td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				Opportunities <br/>
				<table border="1" style="margin-left:10px;" width="90%">
					 <apex:repeat value="{!objAcc.Opportunities}" var="objOpp" rendered="{!objAcc.Opportunities.size > 0}">
						<tr>
							<td><apex:outputField value="{!objOpp.Name}"/></td>
						</tr>
					</apex:repeat>
					<tr style="display:{!IF(objAcc.Opportunities.size == 0,'block','none')}">
						<td><h1>No Opportunities</h1></td>
					</tr>
				</table>
			</td>
		</tr>
		</table> 
		<br/>
	</apex:repeat>
</apex:pageBlock>

 
ECoronaECorona
Nayana & Vivek, thank you for your response! Let me try them, have a great day