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
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.
LBKLBK
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">
<apex:form>
<apex:pageBlock>
    <apex:pageBlockSection>
    <apex:pageBlockSectionItem>
	Stage: <apex:inputField value="{!oppF.StageName}"/>
    </apex:pageBlockSectionItem>
    <apex:pageBlockSectionItem>
		<apex:commandButton action="{!filterRecords}" value="FILTER"/>
    </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
</apex:pageBlock>

<apex:pageblock>
  <apex:sectionHeader title="Opportunity List"/>
  <apex:pageblockTable value="{!lstOpp}" var="opp">
    <apex:column value="{!opp.name}"/>
	<apex:column value="{!opp.CloseDate}"/>
  </apex:pageblockTable>
    </apex:pageblock>
</apex:form>
</apex:page>
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:inputField>
  <apex:pageBlockTable value="{!oppList}" var="opp" id="table">
  <apex:column headerValue="Name" value="{!opp.name}"/>
  <apex:column headerValue="Stage Name" value="{!opp.stagename}"/> 
  
  </apex:pageBlockTable>
  </apex:pageBlock>
  </apex:form>
</apex:page>





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];
       }
}


Thanks 
Ankur Saini