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
Pankaj PariharPankaj Parihar 

product records on vf page

product table
hello 
i need to display this table on vf page on a button click which is inside of an opportunity record.
plz help me with code.
Prakash NawalePrakash Nawale
Hi Pankaj Parihar,

Use below sample code
 
<apex:page standardController="Opportunity" extensions="OpportunityController">
    <apex:form >
        <apex:pageBlock title="Product Details">
                <apex:pageBlockSection columns="1">
              <apex:pageBlockTable Value="{!lLineItems}" var="lineItem">
          <apex:outputField value="{!lineItem.Product.Name}"/>
</apex:pageBlockTable>


            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    </apex:page>

public class OpportunityController{
public string oppId{get;set;}
              public OpportunityController (ApexPages.StandardController controller) { 

         oppId = controllger.getId();
}
public List<opportunityLineItem> getLineItems(){

        return [select id,product.Name from opportunityLineItem where opportunityId =:oppId];

}
}

Please mark this as best answer.

 
Pankaj PariharPankaj Parihar
sir 
this code is showing some errors....User-added imageUser-added image
Aman MalikAman Malik
Hi Pankaj,
You should use apex:relatedList to show all line items. Below is the reference link:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_relatedList.htm

Therefore, below snippet would work for you.
<apex:page standardController="Opportunity" >
    <apex:relatedList list="OpportunityLineItems" />
</apex:page>
- Paste above-mentioned snipped in your page(apex controller not needed).
- Preview the page by clicking preview button on the vf page layout and append the opporunity id followed by your page name like below:
orgbaseUrl/apex/oppTest?id=00656000004qPUo

Hope, the above solution works for you. Kindly let me know in case any query.

Please mark the answer as best if this helps.

Thanks,
Aman



 
Prakash NawalePrakash Nawale
Hi Pankaj,

On line 6 there is typeo mistake, please use below code.
<apex:page standardController="Opportunity" extensions="OpportunityController">
    <apex:form >
        <apex:pageBlock title="Product Details">
                <apex:pageBlockSection columns="1">
              <apex:pageBlockTable Value="{!lLineItems}" var="lineItem">
          <apex:outputField value="{!lineItem.Product.Name}"/>
</apex:pageBlockTable>


            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
    </apex:page>

public class OpportunityController{
public string oppId{get;set;}
              public OpportunityController (ApexPages.StandardController controller) { 

         oppId = controller.getId();
}
public List<opportunityLineItem> getLineItems(){

        return [select id,product.Name from opportunityLineItem where opportunityId =:oppId];

}
}