+ Start a Discussion
Vikas Arora 15Vikas Arora 15 

create a drop down list with "Stagename" field values of Opportunity object

I am new to Salesforce. How do i create a drop down list with "Stagename" field values of Opportunity object. Based on the value selected from drop down list i need to display the filtered Opportunity object records.
Here is the code for you.

Apex Controller
public class opportunityListExtension{
  public opportunityListExtension(){
    oppF = new Opportunity();

  public Opportunity oppF{get;set;}
  public List<Opportunity>  lstOpp{get;set;}
  public void filterRecords(){
    lstOpp = new List<Opportunity>();
    lstOpp = [SELECT Name, CloseDate FROM Opportunity WHERE StageName=:oppF.StageName];

Visualforce page
<apex:page controller="opportunityListExtension">
	Stage: <apex:inputField value="{!oppF.StageName}"/>
		<apex:commandButton action="{!filterRecords}" value="FILTER"/>

  <apex:sectionHeader title="Opportunity List"/>
  <apex:pageblockTable value="{!lstOpp}" var="opp">
    <apex:column value="{!opp.name}"/>
	<apex:column value="{!opp.CloseDate}"/>
Hope this helps.
Ankur Saini 9Ankur Saini 9
Hi  Vikas

Try this:   
<apex:page standardController="Opportunity" extensions="selectOppo">
  <apex:form >
  <apex:pageBlock >
  <apex:inputField value="{!oppObj.stagename}">
  <apex:actionSupport event="onchange" action="{!selectstageOpp}" reRender="table"/>
  <apex:pageBlockTable value="{!oppList}" var="opp" id="table">
  <apex:column headerValue="Name" value="{!opp.name}"/>
  <apex:column headerValue="Stage Name" value="{!opp.stagename}"/> 

public class selectOppo{

public List<opportunity> oppList{get;set;}
public opportunity oppObj{get;set;}
    public selectOppo(ApexPages.StandardController controller) {
     oppList= new List<opportunity>();
     oppObj= new opportunity();

    public void selectstageOpp(){
         oppList=[select id, name,stagename from opportunity where stagename=:oppObj.stagename];

Ankur Saini