This is my VF page "TestPage":

<apex:page standardController="Account">
<c:TestComponent recordId="{!account}" />

Visual Force component "Test Component":

<apex:component controller="Taccount">
<apex:attribute name="recordId" description="Record Id to show field history for." type="sobject"  assignTo="{!record}" required="true"/>
 <apex:relatedList list="Opportunities"/> 
<apex:relatedList list="record.Opportunities"/> 

Problem is that <apex:relatedList list="Opportunities"/> or <apex:relatedList list="record.Opportunities"/> is not showed in the main page"TestPage".

Do you know how can i show, in the main page, a related list added in a component?

Thanks in advance for any advice.


You can do this by setting the subject attribute of apex:relatedList.

For example:

The component can be written to accept the account record as an attribute passed into it.

  <apex:attribute name="acctRec" type="Account" description="The Account passed in"/>
  <apex:relatedList subject="{!acctRec}" list="Opportunities"/>

The VF Page can pass the account record.

<apex:page standardController="Account">
    <c:testComponent acctRec="{!account}" />

The result will be that the Opportunities for the Account specified by the id parameter will be displayed within the component. Opportunities related list

  • Much better to only accept the Id. Only pass what you need! – Adrian Larson Jan 20 '15 at 23:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.