+ Start a Discussion
Prallavi DuaPrallavi Dua 

Display Opportunities and its related Products in the same VF page

I have a below requirenment
  1. Render VF page as PDF
  2. Create a custom button on opportunity object which will redirect user to a VF page which will populate some opportunity fields and a table showing related opportunity product details in PDF form.
  3. Opportunity fields to populate
    • Opportunity Name
    • Parent Account Name
  4. There will be another section on this page which will populate the details of all the products related to opportunity.
  5. Show product details in a table populating following opportunity product fields
  6. This VF page should open in PDF format.
Can anyone help me!!!!!!!!!!!!!!
Thanks in Advance

Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Prallavi Dua,

Please refer the below code.

VisualForce Page:
<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}"/>
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;

User-added image

hope it helps.

Please mark it as best answer if the information is informative.

Rahul Kumar
Prallavi DuaPrallavi Dua
Hi Rahul Kumar,
 I already saw this code, this is not my requirement.
Please read the requirement properly.

Thank you.