You need to sign in to do that
Don't have an account?
Brandon Nelson
Return sub query data in apex visualforce page
I have a SOQL query wrote out, but I can't (Don't know how) to access it in VisualForce. Can someone please help me with the Apex page? I can return the main columns but I don't know how to return the sub query in the columns?
APEX CLASS CODE
public with sharing class DisplayAttachments{ public List<Account> Records {get; set;} public DisplayAttachments(){ String userId = userinfo.getUserName(); Records = [select Id,Name,(Select Id,Name from Attachments) From Account Where CreatedBy.Name = iserId]; } }
VISUALFORCE PAGE
<apex:page controller="DisplayAttachments"> <apex:pageBlock title="My Attachments"> <apex:pageBlockTable value="{!Records}" var="Record"> <apex:column > <apex:facet name="header">Client ID</apex:facet> <apex:outputText value="{!Record.ID}"/> </apex:column> <apex:column > <apex:facet name="header">Client Name</apex:facet> <apex:outputText value="{!Record.Name}"/> </apex:column> <apex:column > <apex:facet name="header">Attachment ID</apex:facet> <apex:outputText value="{!Record.ID}"/> </apex:column> <apex:column > <apex:facet name="header">Attachment Name</apex:facet> <apex:outputText value="{!Record.Name}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
APEX CLASS CODE
public with sharing class DisplayAttachments{ public List<Account> Records {get; set;} public DisplayAttachments(){ String userId = userinfo.getUserName(); Records = [select Id,Name,(Select Id,Name from Attachments) From Account Where CreatedBy.Name = iserId]; } }
VISUALFORCE PAGE
<apex:page controller="DisplayAttachments"> <apex:pageBlock title="My Attachments"> <apex:pageBlockTable value="{!Records}" var="Record"> <apex:column > <apex:facet name="header">Client ID</apex:facet> <apex:outputText value="{!Record.ID}"/> </apex:column> <apex:column > <apex:facet name="header">Client Name</apex:facet> <apex:outputText value="{!Record.Name}"/> </apex:column> <apex:column > <apex:facet name="header">Attachment ID</apex:facet> <apex:outputText value="{!Record.ID}"/> </apex:column> <apex:column > <apex:facet name="header">Attachment Name</apex:facet> <apex:outputText value="{!Record.Name}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:page>
you can do it by ussing nested page <apex:pageblockTable>
and also use createdById insted of createBy.Name
i update you code try this onces result
Thanks
mark it best answer if it helps you so it make proper solution for others in future :)
let me inform if it helps you.