+ Start a Discussion
LearnerrrLearnerrr 

Not able to see the list of stageName of opportunity in select list:--->I want to create list of opportunity stage and by selecting a stage from the list ,details of opportunity will be display for the same stage

<apex:page controller="OppotunityByList" >
  <apex:form >
        <apex:pageBlock title="Display Opportunity Details: ">
            
            <apex:pageBlockSection >
            <apex:outputLabel value="opportunity Name: " />
            
            <apex:selectlist value="{!oppid}" size="1" >
                <apex:selectOptions value="{!oppnames}" />
                <apex:actionSupport action="{!getDetails}" event="onchange" rerender="display"/>
            </apex:selectlist>
            </apex:pageBlockSection>
          
                <apex:pageBlockSection id="display" title="Account Details">
                     <apex:pageBlockTable value="{!SelectedOpp}" var="a">   
  
                    <apex:column HeaderValue="Name" value="{!a.Name}"/>
                    <apex:column HeaderValue="Stage Name" value="{!a.StageName}"/>
                      </apex:pageBlockTable> 
                </apex:pageBlockSection>    
        
           
           
        </apex:pageBlock>
    </apex:form>
 
public class OppotunityByList {

    public String oppnames { get; set; }
    public String oppid { get; set; }
    public Opportunity SelectedOpp{get;set;}
    
    public list<selectoption> getoppnames() {
        
        list<selectoption> accoptions = new list<selectoption>();
        for (opportunity p : [select id, stageName from opportunity]){
            accoptions.add(new selectoption(p.id, p.name));
        }  
        return accoptions;
    } 
    
    public void  getDetails() {
        
        SelectedOpp = new Opportunity();
        SelectedOpp = [SELECT id, Name, stageName FROM Opportunity WHERE stageName=:oppid ];
        
    }
   
   
}

 
Ravi Dutt SharmaRavi Dutt Sharma
Hi Sweta,

Replace your getoppnames method with below:
 
public list<selectoption> getoppnames() {
        
        list<selectoption> accoptions = new list<selectoption>();
		Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
		List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
		{
			accoptions.add(new SelectOption(f.getLabel(), f.getValue()));
		}   
        return accoptions;
    }
 Please mark this as the best answer if it solves your problem. Thanks.
 
Ravi Dutt SharmaRavi Dutt Sharma
Some more changes required. Please use below code:
 
<apex:page controller="OppotunityByList" >
    <apex:form >
        <apex:pageBlock title="Display Opportunity Details: ">
            
            <apex:pageBlockSection >
                <apex:outputLabel value="opportunity Name: " />
                
                <apex:selectlist value="{!oppid}" size="1" >
                    <apex:selectOptions value="{!oppnames}" />
                    <apex:actionSupport action="{!getDetails}" event="onchange" rerender="display"/>
                </apex:selectlist>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="display" title="Account Details">
                <apex:pageBlockTable value="{!SelectedOpp}" var="a">   
                    
                    <apex:column HeaderValue="Name" value="{!a.Name}"/>
                    <apex:column HeaderValue="Stage Name" value="{!a.StageName}"/>
                </apex:pageBlockTable> 
            </apex:pageBlockSection>    
            
            
            
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class OppotunityByList {

    list<selectoption> oppnames { get; set; }
    public String oppid { get; set; }
    public Opportunity SelectedOpp{get;set;}
    
    public list<selectoption> getoppnames() {
        
        oppnames = new list<selectoption>();
		Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
		List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for( Schema.PicklistEntry f : ple)
		{
			oppnames.add(new SelectOption(f.getLabel(), f.getValue()));
		}   
        return oppnames;
    } 
    
    public void  getDetails() {
        
        SelectedOpp = new Opportunity();
        SelectedOpp = [SELECT id, Name, stageName FROM Opportunity WHERE stageName=:oppid ];
        
    }
   
   
}

 
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sweta,

Please try the below code, it is working fine. Kindly modify the code as per your requirement.
 
Visualforce:
<apex:page controller="OppStageC">
    <apex:form >
        <apex:pageBlock title="Display Opportunity Details: ">
            
            <apex:pageBlockSection >                
                <apex:inputField value="{!opp.StageName}">
                    <apex:actionsupport event="onchange" action="{!method1}" rerender="display"/>
                </apex:inputField>
            </apex:pageBlockSection>
            
            <apex:pageBlockSection id="display" title="Account Details">
                <apex:pageBlockTable value="{!opps}" var="a">   
                    
                    <apex:column value="{!a.Name}"/>
                    <apex:column value="{!a.StageName}"/>
                </apex:pageBlockTable> 
            </apex:pageBlockSection>                
            
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class OppStageC {
    
    public Opportunity opp {get;set;}
    public List<Opportunity> opps {get;set;}
    
    public OppStageC(){
        opp = new Opportunity();
        opps = new List<Opportunity>();
    }
    
    public pageReference  method1() {      
        opps = [SELECT Name, StageName FROM Opportunity WHERE StageName = :opp.stagename];
        return null;
    } 
}


I hope it helps you.

Kindly let me inform if it helps you and close your query by marking it as solved so that it can help others in future.

Thanks and Regards,
Khan Anas​