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
UrvikUrvik 

Display opportunity product related list on visualforce page for oppotunity

Hi All,
How do I display opportunity product related list on a visualforce page? I am trying to use <apex:relatedlist> markup but its not working. I guess its because both are standard objects. What is the best way to display opportunity product related list on visualforce page? How about using <apex:facet> markup. But Opportunity.Product2 gives me an error (invalid field).

Thanks,
Rick
CloudGeekCloudGeek
Hello Rick,

You may find this helpful :
 
<apex:page controller="myOpptyController" tabStyle="Opportunity">
    
    <apex:pageBlock title="opportunity product related list">

    <apex:pageBlockTable value="{!opptyList}" var="div">
          
          <apex:column >
                    <apex:pageBlockTable value="{!div.OpportunityLineItems}"  var="custom">
                    <apex:column value="{!custom.Quantity}"/>
                    <apex:column value="{!custom.UnitPrice}"/>
                    <apex:column value="{!custom.TotalPrice}"/>
                    <apex:column value="{!custom.PricebookEntry.Name}"/>
                    <apex:column value="{!custom.PricebookEntry.Product2.Family}"/>
                </apex:pageBlockTable>
        </apex:column>
          
          
 </apex:pageBlockTable>
</apex:pageBlock>
    
</apex:page>


Controller :
 
public class myOpptyController {

    public List<Opportunity> opptyList;
    
    public myOpptyController() {

    opptyList = [SELECT Id,Name,Account.Name, 
                                  (SELECT Quantity, UnitPrice, TotalPrice,PricebookEntry.Name, PricebookEntry.Product2.Family FROM OpportunityLineItems) 
                        FROM Opportunity WHERE Id =: ApexPages.currentPage().getParameters().get('opptyID')];
    
        System.debug('opptyList ='+opptyList);

    }
    
    public List<Opportunity> getopptyList() {
        return opptyList;
    }
    
}


You will get output like:

User-added image



Note: Mark this is as Solution if this helps in resolving your issue.
Nithin VargheseNithin Varghese
Give the value of list as "OpportunityLineItem" .
Like this :-
<apex:relatedList list="OpportunityLineItem" />