I want to add Drill down functionality on Opportunity Name link.. means when someone click on link then all the PRODUCT Will be display in new page which is added in single Opportunity.

Here is my Controller...But i am not understanding that where should i write Code in controller and VF Page for display List of Product.


public class ListOfEditionOpportunity {
    public List<Edition__c> accList {get; set;} 
    public string SelectedEdition {get;set;}
    public List<Opportunity> opptyList {get; set;}
    List<OpportunityLineItem> myProduct{get;set;}
    public List<SelectOption> getEditionList(){
        List<SelectOption> listValue = new List<SelectOption>();
        listValue.add(new SelectOption('','--None--'));
        for(Edition__c L:accList){
            listValue.add(new SelectOption(l.id,l.name));
        return listValue;
    //Method to get Opportunity List Detail
    public List<Opportunity> getOpptyRecord(){
        List<Opportunity> myOpp = new List<Opportunity>([select id,Name,Account.name,
                                                         from Opportunity WHERE Edition__r.id = :SelectedEdition ]);
     return myOpp;
    public pageReference getDetails(){
        opptyList = new List<Opportunity>();
        for(Opportunity o:getOpptyRecord()){
             return null;

       // Constructor of Class
    public ListOfEditionOpportunity(apexPages.StandardController controller){
        opptyList = new List<Opportunity>();
        accList = new List<Edition__c>([SELECT Id,Name FROM Edition__c]);
        SelectedEdition = '';


<apex:page standardController="Opportunity" extensions="ListOfEditionOpportunity" tabStyle="Edition__c">

      <apex:form >
          <apex:pageBlock title="All Edition Details">

             <apex:outputLabel ><H2>Select Edition From the List</H2></apex:outputLabel>
             <apex:selectList value="{!SelectedEdition}" size="1">
                     <apex:selectOptions value="{!EditionList}"/>
                <apex:actionSupport action="{!getDetails}" event="onchange" id="PBS2"/>

      <apex:pageblock >
      <apex:pageblockSection id="PBS1" title="List of Opportunity " collapsible="false"  columns="1" >
          <apex:pageblockTable value="{!opptyList}" Var="o" Width="100%">

              <apex:column HeaderValue="Action">

                  <apex:commandLink value="Edit" action="{!URLFOR($Action.Opportunity.Edit,o.id)}"/>
                  <apex:commandLink value="Delete" action="{!URLFOR($Action.Opportunity.Delete,o.id)}" />   

              <apex:column headerValue="Opportunity Name">
                  <apex:outputLink value="/{!o.id}">{!o.name}</apex:outputLink>
              <apex:column HeaderValue="Account Name">
                  <apex:outputLink value="/{!o.AccountId}">{!o.Account.Name}</apex:outputLink>
              <apex:column HeaderValue="Opportunity Record Type" value="{!o.RecordType.Name}"/>
              <apex:column HeaderValue="Close Date" value="{!o.CloseDate}"/>
              <apex:column headerValue="Stage Name" value="{!o.StageName}"/>
              <apex:column HeaderValue="Account Owner Formula" value="{!o.Account_Owner_Formula__c}"/>
              <apex:column HeaderValue="Created Date" value="{!o.CreatedDate}"/>

Kindly Help me out from this requirement I'm new in Salesforce Development. Please provide me some codes with example. Thank you to all.

1 Answer 1


Place a command link in your existing opportunity listview page to redirect to your new page (viewProducts here).

VF page

<apex:commandLink value="View Products" action="{!redirectView}">
    <apex:param name="oppId" value="{!o.id}" assignTo="{!oppId}" />

Apex class - a method in your existing class

public pageReference redirectToProductView(){

    PageReference pageRef = new PageReference('/apex/viewProducts?Id='+oppId);
    return pageRef;

The products list VF page (viewProducts here) should look like this

    <apex:pageblockTable value="{!opptyProductList}" Var="opptyProduct" Width="100%">
        <apex:column HeaderValue="Action" value="{!opptyProduct.ProductCode}" />

Apex class to use as controller for VF page(viewProducts)

public class viewProductController{

    public List<OpportunityLineItem> opptyProductList {get;set;}    

    public viewProductController(){

        String oppId = ApexPages.currentPage().getParameters().get('Id');
        opptyProductList = new List<OpportunityLineItem>([SELECT Id,ProductCode
                                                            FROM OpportunityLineItem
                                                            WHERE OpportunityId =: oppId]);

I have used only one field to display as of now. you can include as your requirement.

  • Hi, Sikha Baid, I implemented this code and Logic is cleared but after redirecting on new page Products is not showing or fetching and I saw in URL showing like = " c.cs84.visual.force.com/apex/productsListVfPage?Id=null " id = null what should i do even i checked my SOQL Query in Query Editor that is working properly. Please clarify from this issue and thank you for your response. Oct 16, 2017 at 20:45
  • place the code updates you have made. The parameter value is going null, just check the opportunity Id is queried and passing correctly.
    – Sikha Baid
    Oct 17, 2017 at 3:05
  • Thank you Sikha Baid.. Finally i achieved my business requirement. Oct 18, 2017 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .