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
Emma Diaz 12Emma Diaz 12 

VF to show Parent List on Child

I have a custom object US_Resource_Request__c that has a Master Detail relationship to the Opportunity. I would like to show the Products related list on the US_Resource_Request__c. 
I have tried 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="Product2" subject="{US_Resource_Request__c.Opportunityid}"/>
</apex:page>
And am getting the following error "Error: Formula expression is required for attribute subject in <apex:relatedList> in Products_related_list at line 2 column 85"
 
Best Answer chosen by Emma Diaz 12
Deepak Kumar 138Deepak Kumar 138
Try this corrected the relationship name - 
 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="OpportunityLineItems" subject="{!US_Resource_Request__c.OpportunityID__c}"/>
</apex:page>

 

All Answers

Deepak Kumar 138Deepak Kumar 138
Try this - 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="Product2" />
</apex:page>

or 
 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="Product2" subject="{!US_Resource_Request__c.Opportunityid}"/>
</apex:page>

Note - Mark this as best answer if it solves your issue.
 
Pramodh KumarPramodh Kumar
You wont get products directly in your custom object. The expression you are using is wrong because there is no relation to the custom object and product.

And more over related list means the childs of that particular object not the parents object related list.

Thanks,
Pramodh.
Emma Diaz 12Emma Diaz 12

Hi Deepak,
So I tweaked the code you gave me a litte 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="OpportunityLineItem" subject="{!US_Resource_Request__c.OpportunityID__c}"/>
</apex:page>
and am receiving an error that OpportunityLineItem isn't a child object of the Opportunity. 

Any thoughts?

Thanks!

Emma

Deepak Kumar 138Deepak Kumar 138
Try this corrected the relationship name - 
 
<apex:page standardController="US_Resource_Request__c">
<apex:relatedList list="OpportunityLineItems" subject="{!US_Resource_Request__c.OpportunityID__c}"/>
</apex:page>

 
This was selected as the best answer
Emma Diaz 12Emma Diaz 12
This worked!!! Thanks soooooo much!!!