You need to sign in to do that
Don't have an account?
Tabitha Oostra 1
visualforce displaying records relatedlists apex code shows blank screen
I am trying to follow the directions for the Developer's Beginner Module, I'm on: Displaying Records, Fields and Tables.
The instructions seem to be missing something as I can't get my apex code to display the records as indicated in the instructions or I'm doing it incorrectly and the instructions aren't missing anything. But I think there is a missing piece.
Here's the code:
<apex:detail standardController="Account" >
<apex:relatedList list="Contacts"/>
<apex:relatedList list="Opportunities" pageSize="5"/>
</apex:detail>
My Preview screen comes up blank. Your help would be appreciated to know what I'm missing.
Thanks.
T.
The instructions seem to be missing something as I can't get my apex code to display the records as indicated in the instructions or I'm doing it incorrectly and the instructions aren't missing anything. But I think there is a missing piece.
Here's the code:
<apex:detail standardController="Account" >
<apex:relatedList list="Contacts"/>
<apex:relatedList list="Opportunities" pageSize="5"/>
</apex:detail>
My Preview screen comes up blank. Your help would be appreciated to know what I'm missing.
Thanks.
T.
Hopefully the code below can help you.
<apex:page standardController="Account">
<apex:detail relatedList="false"/>
<apex:relatedList list="Contacts"/>
<apex:relatedList list="Opportunities" pageSize="5"/>
</apex:page>
All Answers
Create a page which displays a subset of Opportunity fields using apex:outputField components. Bind the Name, Amount, Close Date and Account Name fields to the apex:outputField components.
The page must be named 'OppView'.
It must reference the Opportunity standard controller.
It must have an apex:outputField component bound to the Opportunity Name.
It must have an apex:outputField component bound to the Opportunity Amount.
It must have an apex:outputField component bound to the Opportunity Close Date.
It must have an apex:outputField component bound to the Account Name of the Opportunity.
In this case you would not need to use apex:detail.
Looking at the request we need to use the opportunity standard controller so we can access the fields.
We also want to use a block section to display thie fields requested.
It should look like th ecode below.
<apex:page standardController="Opportunity">
<apex:pageBlock title="Opportunities">
<apex:pageBlockSection >
<apex:outputField value="{! Opportunity.Name}"/>
<apex:outputField value="{! Opportunity.Amount}"/>
<apex:outputField value="{! Opportunity.CloseDate}"/>
<apex:outputField value="{! Opportunity.Account.Name}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Please note the reason your page is blank is because you are using <apex:detail standardController="Account" > not
<apex:page standardController="Account" >.
Let me know if this helps and mark as best answer if it does :)
Display Related Lists
Use <apex:relatedList> to display lists of records related to the current record.
The <apex:detail> component displays the details of a particular record, as well as lists of related records, such as contacts, cases, opportunities, and so on. This might be too much, so you can remove those related lists, and then add back just a few, using a different coarse-grained component.
Revise the markup to omit related lists by adding relatedList="false" to the <apex:detail> component.
1 <apex:detail relatedList="false"/>
The account record’s details are still displayed, but the related lists are gone.
Below the <apex:detail/> line, add the following markup.
1 <apex:relatedList list="Contacts"/>
2 <apex:relatedList list="Opportunities" pageSize="5"/>
Your page should now display two related lists, for contacts and opportunities. Also notice that you can configure each related list independently, by changing attributes on just that component.
The <apex:relatedList> component is another coarse-grained component, but it’s lower level than <apex:detail>. That is, <apex:detail> shows many related lists at once (or none), while <apex:relatedList> lets you go one by one. This lets you show only the related lists that you’re interested in, and you can customize the display of each related list individually.
I just can't seem to get this to work and here is the way I laid out the apex code. I'm not sure what I'm doing wrong.
Here's the code I used:
<apex:detail standardController="Account" >
<apex:relatedList list="Contacts"/>
<apex:relatedList list="Opportunities" pageSize="5"/>
</apex:detail>
Thanks,
T.
Hopefully the code below can help you.
<apex:page standardController="Account">
<apex:detail relatedList="false"/>
<apex:relatedList list="Contacts"/>
<apex:relatedList list="Opportunities" pageSize="5"/>
</apex:page>
Much appreciated!
T.