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
Geetha BGeetha B 

how to display oppourtunity records based on oppourtunity stage in vf page

I need to c
Best Answer chosen by Geetha B
praveen murugesanpraveen murugesan
Hi Geetha,

Sry for the delay..

Try this.

public with sharing class TestCodeController {

      public List<selectOption> getSelectOptions() { 
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('--Select--','--Select--'));
        options.add(new SelectOption('Prospecting','Prospecting'));
        options.add(new SelectOption('Qualification','Qualification'));
        options.add(new SelectOption('Needs Analysis','Needs Analysis'));
        options.add(new SelectOption('Value Proposition','Value Proposition'));
        options.add(new SelectOption('Id. Decision Makers','Id. Decision Makers'));
        options.add(new SelectOption('Perception Analysis','Perception Analysis'));
        options.add(new SelectOption('Proposal/Price Quote','Proposal/Price Quote'));
        options.add(new SelectOption('Negotiation/Review','Negotiation/Review'));
        options.add(new SelectOption('Closed Won','Closed Won'));
        options.add(new SelectOption('Closed Lost','Closed Lost'));
       
        return options;
      }
    
      public String selectedVal{get;set;}
      public list<Opportunity> Opps{get;set;} 
      public TestCodeController()
      {
      }

      public pageReference oppList()
      {
      if(selectedVal !=null) 
      {
         Opps= [select name,type,CloseDate from Opportunity where StageName =: selectedVal];
      }
      return null;

      } 
  
}

<apex:page controller="TestCodeController">
  <apex:form > 
   Stage Name  <apex:SelectList id="List" value="{!selectedVal}" size="1">
                    <apex:actionSupport action="{!oppList}" event="onchange"
                       reRender="pb"/>
                    <apex:selectOptions value="{!selectOptions}" />
                 </apex:SelectList>

           <apex:pageBlock id="pb" >
          <apex:pageBlockTable value="{!opps}" var="v">
            <apex:column value="{!v.name}"/>
            <apex:column value="{!v.type}"/>
            <apex:column value="{!v.CloseDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
</apex:form> 
</apex:page>

Here we are not using standard controller so we need to hardcode the picklist.

Mark this as best answer if its helps.

Thanks.

All Answers

praveen murugesanpraveen murugesan
Hi Geetha,

This will help you

http://stackoverflow.com/questions/8087392/salesforce-get-list-of-closed-opportunity-stages

Thanks
Geetha BGeetha B
Hi pravven,

        How to pass the selected picklist values from page to controller.

Thank You.
praveen murugesanpraveen murugesan
HI,
public with sharing class PickListController {

    public String selectedcountry { get; set; }

    public list<selectoption>  lstoptions { get; set; }
    
    public PickListController()
    {
      list<selectoption> options  = new list<selectoption>();
      options.add(new selectoption('','select country'));
      options.add(new selectoption('India','IND'));
      options.add(new selectoption('US','US'));
      options.add(new selectoption('Canada','CA'));
      lstoptions = options;
    
    }
}



<apex:page controller="PickListController">
  <apex:form >
 
                    <apex:SelectList id="List" value="{!selectedcountry}" size="1">  <!-- selected value will stored in this variable -->
                        <apex:selectOptions value="{!lstoptions}"/> 
                    </apex:SelectList>
                    
      
  </apex:form>
</apex:page>

In this example,

selected value is stored in selectedcountry.

Thanks

Geetha BGeetha B
Hi pravven,
                     Please look into my code,
          
<apex:page controller="DisplayOppRec">
  <apex:form >
      Stage Name <apex:inputField value="{!opp.StageName}">
      <apex:actionsupport event="onchange" rerender="pb"/>
      </apex:inputfield>
         <apex:pageBlock id="pb" >
          <apex:pageBlockTable value="{!opps}" var="v">
            <apex:column value="{!v.name}"/>
            <apex:column value="{!v.type}"/>
            <apex:column value="{!v.CloseDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
  </apex:form>
</apex:page>
-------------------------------------------------------------------------
public class DisplayOppRec
{
  public Opportunity  opp{get;set;}
  public list<opportunity> opps = new list<opportunity>();
  public list<opportunity> getopps()
  {
   
    opps = [select name,type,CloseDate from opportunity where StageName = 'Prospecting'];
    system.debug('display list values-----------'+opps);
    return opps;
  } 
}
Geetha BGeetha B
I am getting null object dereferencing error from above code
Geetha BGeetha B
sorry here is the class
public class DisplayOppRec
{
  public Opportunity  opp{get;set;}
  public list<opportunity> opps = new list<opportunity>();
  public list<opportunity> getopps()
  {
   
    opps = [select name,type,CloseDate from opportunity where StageName =: opp.stagename];
    system.debug('display list values-----------'+opps);
    return opps;
  } 
}
praveen murugesanpraveen murugesan
Hi,

I am Praveen not pravven :),

here is the code

<apex:page controller="PickListController">
  <apex:form >
 
      Stage Name <apex:inputText value="{!StageName}">
      <apex:actionsupport event="onchange" rerender="pb"/>
      </apex:inputText>
         <apex:pageBlock id="pb" >
          <apex:pageBlockTable value="{!opps}" var="v">
            <apex:column value="{!v.name}"/>
            <apex:column value="{!v.type}"/>
            <apex:column value="{!v.CloseDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>

  </apex:form>
</apex:page>

public with sharing class PickListController {


     public string stagename{get;set;}
  public list<opportunity> opps = new list<opportunity>();
  public list<opportunity> getopps()
  {
   
    opps = [select name,type,CloseDate from opportunity where StageName =: stagename];
    system.debug('display list values-----------'+opps);
    return opps;
  } 
}

Mark this as best answer if its helps.

Thanks
Geetha BGeetha B
Praveen stage name is the oppourtunity stage name , i should get the pick list values of stagename from oppourtunity.
sfdc@isha.ax1814sfdc@isha.ax1814
Hi
 

<apex:page controller="DisplayOppRec">
  <apex:form >
      Stage Name <apex:inputField value="{!opp.StageName}">
                      <apex:actionsupport event="onchange" action="{!method1}" rerender="dd"/>
                  </apex:inputfield>
         <apex:pageBlock >
         <apex:outputPanel id="dd">
          <apex:pageBlockTable value="{!opps}" var="v" id="pb">
            <apex:column value="{!v.name}"/>
            <apex:column value="{!v.type}"/>
            <apex:column value="{!v.CloseDate}"/>
          </apex:pageBlockTable>
          </apex:outputPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>



class:

public with sharing class DisplayOppRec {
public Opportunity  opp{get;set;}
public list<opportunity> opps{get;set;}

public DisplayOppRec(){
opps=new list<opportunity>();
  opp=new opportunity();
}
    public pagereference method1()
   
  {
 
  system.debug('--opp.stagename--'+opp.stagename);
 
   opps = [select name,type,CloseDate from opportunity where StageName =:opp.stagename];
    system.debug('@@@@@@@@@@@@@result'+opps);
   
   return null;
   
  }
 
}

Mark this as best answer if its helps.

Thanks

Geetha BGeetha B
I am still getting the same null pointer exception
can any one give solution for this please

praveen murugesanpraveen murugesan
Hi Geetha,

Sry for the delay..

Try this.

public with sharing class TestCodeController {

      public List<selectOption> getSelectOptions() { 
        List<selectOption> options = new List<selectOption>();
        options.add(new selectOption('--Select--','--Select--'));
        options.add(new SelectOption('Prospecting','Prospecting'));
        options.add(new SelectOption('Qualification','Qualification'));
        options.add(new SelectOption('Needs Analysis','Needs Analysis'));
        options.add(new SelectOption('Value Proposition','Value Proposition'));
        options.add(new SelectOption('Id. Decision Makers','Id. Decision Makers'));
        options.add(new SelectOption('Perception Analysis','Perception Analysis'));
        options.add(new SelectOption('Proposal/Price Quote','Proposal/Price Quote'));
        options.add(new SelectOption('Negotiation/Review','Negotiation/Review'));
        options.add(new SelectOption('Closed Won','Closed Won'));
        options.add(new SelectOption('Closed Lost','Closed Lost'));
       
        return options;
      }
    
      public String selectedVal{get;set;}
      public list<Opportunity> Opps{get;set;} 
      public TestCodeController()
      {
      }

      public pageReference oppList()
      {
      if(selectedVal !=null) 
      {
         Opps= [select name,type,CloseDate from Opportunity where StageName =: selectedVal];
      }
      return null;

      } 
  
}

<apex:page controller="TestCodeController">
  <apex:form > 
   Stage Name  <apex:SelectList id="List" value="{!selectedVal}" size="1">
                    <apex:actionSupport action="{!oppList}" event="onchange"
                       reRender="pb"/>
                    <apex:selectOptions value="{!selectOptions}" />
                 </apex:SelectList>

           <apex:pageBlock id="pb" >
          <apex:pageBlockTable value="{!opps}" var="v">
            <apex:column value="{!v.name}"/>
            <apex:column value="{!v.type}"/>
            <apex:column value="{!v.CloseDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlock>
</apex:form> 
</apex:page>

Here we are not using standard controller so we need to hardcode the picklist.

Mark this as best answer if its helps.

Thanks.
This was selected as the best answer
sfdc@isha.ax1814sfdc@isha.ax1814
Hi Geetha,

i tried in my developer eddition it is working fine once again try it it will work.i changed some code and tried it.if u r not using standard controller then go for the praveen code.



 User-added image


thanks

Geetha BGeetha B
Thank You praveen your code is working .

Isha i want to know what  changes u made in ur code .

Geetha BGeetha B
Paveen cant we get the  standard picklist field value to controller

without creating custom one

praveen murugesanpraveen murugesan
Geetha,

Good to hear.

I hope we can't.  I have tried in many ways i can't pass the value to controller. But I am not 100 percent sure.

Thanks.
Geetha BGeetha B
Thank You praveen
        
                   Thank you so much for spending time for my post.