+ Start a Discussion
Kevin RadmallKevin Radmall 

SOQL - Child Relationship showing up on Visual Force Page

Hi Everyone,

I am having an issue getting child recording showing up on a visual force page

Here is my current controller and visual forcepage code


public class MRAController { List<Account> Acts = [Select a.Name, (Select Id , Name, CreatedDate From Opportunities ORDER BY CreatedDate DESC LIMIT 1), (Select Title, CreatedDate From NotesAndAttachments ORDER BY CreatedDate DESC LIMIT 1), (Select Description, CreatedDate From ActivityHistories ORDER BY CreatedDate DESC LIMIT 1) From Account a WHERE OWNERID ='00570000003FI8tAAG' LIMIT 1]; List<Account> Acts2 = [Select a.Name, (Select Id, Name, CreatedDate From Opportunities ORDER BY CreatedDate DESC LIMIT 1), (Select Title, CreatedDate From NotesAndAttachments ORDER BY CreatedDate DESC LIMIT 1), (Select Description, CreatedDate From ActivityHistories ORDER BY CreatedDate DESC LIMIT 1) From Account a WHERE OWNERID ='00570000002ZCzzAAG']; public List<Account> getActs(){ return Acts; } public List<Account> getActs2(){ return Acts2; } }

<apex:page sidebar="false" controller="MRAController" >
<apex:form >   
 
    <apex:tabPanel activeTabClass="Blue" switchtype="ajax" >
    <apex:tab label="Jim Bridger" LabelWidth="100" id="tb1"><apex:pageBlock >
    <apex:pageBlockTable value="{!Acts}" var="a" ID="table">
    <apex:Column value="{!a.ID}" Width="120"/>
    <apex:Column value="{!a.Name}"/>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:tab>
 <apex:tab label="Jim Bridger 2" LabelWidth="100" id="tb2">
    <apex:pageBlock >
    <apex:PageBlockTable value="{!Acts2}" var="b">
    <apex:column value="{!b.ID}"/>
    <apex:column value="{!b.Name}"/>
    </apex:PageBlockTable>
    </apex:pageBlock>
    </apex:tab> 


</apex:tabPanel>
    </apex:form>
</apex:page>

I am having an issue displaying the opportunites

Right now I can only get the Account Information to display and can not get the Opportunity Information to display

Account Name - Opportunity ID - Opportunity Name - Note Title - Created Date - Activity Title - Created Date

 
Best Answer chosen by Kevin Radmall
Terence_ChiuTerence_Chiu
Not sure if this will work for you, but based on what you are trying to accomplish you can try add an apex:repeat within the page block table that will iterate through any Opportunities related to the account record. This could make the UI quite messy as some accounts may or may not have opportunities.


 
<apex:page sidebar="false" controller="MRAController" >
<apex:form >   
 
    <apex:tabPanel activeTabClass="Blue" switchtype="ajax" >
    <apex:tab label="Jim Bridger" LabelWidth="100" id="tb1"><apex:pageBlock >
    <apex:pageBlockTable value="{!Acts}" var="a" ID="table">
    <apex:Column value="{!a.ID}" Width="120"/>
    <apex:Column value="{!a.Name}"/>
       <apex:repeat value="{!a.Opportunities}" var="opp">
                <apex:column value="{!opp.Name}">
                 <apex:column value="{!opp.Id}"> 
        </apex:repeat>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:tab>
 <apex:tab label="Jim Bridger 2" LabelWidth="100" id="tb2">
    <apex:pageBlock >
    <apex:PageBlockTable value="{!Acts2}" var="b">
    <apex:column value="{!b.ID}"/>
    <apex:column value="{!b.Name}"/>
    </apex:PageBlockTable>
    </apex:pageBlock>
    </apex:tab> 


</apex:tabPanel>
    </apex:form>
</apex:page>

 

All Answers

Terence_ChiuTerence_Chiu
Kevin, how do you want the child object records to be displayed ? You have two pageblock tables displaying account records owned by users from two different user accounts. Did you potentially just need two seperate tables that displays Opportunities that are related to Accounts that User Account 1 owners and the Notes and attachment records related to the Account that User Account 2 owns ?

 
Kevin RadmallKevin Radmall
Hi Terence,

So I have 7 users that I want each on seperate tabs all need to display the same information within their tabs.

I would like the child records to simply be right next to the master record if it exsist, if not just to display blank.



 
Terence_ChiuTerence_Chiu
Not sure if this will work for you, but based on what you are trying to accomplish you can try add an apex:repeat within the page block table that will iterate through any Opportunities related to the account record. This could make the UI quite messy as some accounts may or may not have opportunities.


 
<apex:page sidebar="false" controller="MRAController" >
<apex:form >   
 
    <apex:tabPanel activeTabClass="Blue" switchtype="ajax" >
    <apex:tab label="Jim Bridger" LabelWidth="100" id="tb1"><apex:pageBlock >
    <apex:pageBlockTable value="{!Acts}" var="a" ID="table">
    <apex:Column value="{!a.ID}" Width="120"/>
    <apex:Column value="{!a.Name}"/>
       <apex:repeat value="{!a.Opportunities}" var="opp">
                <apex:column value="{!opp.Name}">
                 <apex:column value="{!opp.Id}"> 
        </apex:repeat>
    </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:tab>
 <apex:tab label="Jim Bridger 2" LabelWidth="100" id="tb2">
    <apex:pageBlock >
    <apex:PageBlockTable value="{!Acts2}" var="b">
    <apex:column value="{!b.ID}"/>
    <apex:column value="{!b.Name}"/>
    </apex:PageBlockTable>
    </apex:pageBlock>
    </apex:tab> 


</apex:tabPanel>
    </apex:form>
</apex:page>

 
This was selected as the best answer
Kevin RadmallKevin Radmall
Thank You Terence_Chiu That did the Trick!