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
ajith kumar 35ajith kumar 35 

get id's of slected values of selectlist

I need the id of selected values from selectlist in my apex

page:
<apex:page controller="test">
        <apex:form>
            <apex:pageBlock>
                <apex:pageBlockSection>
                    <apex:OutputPanel >
                        <apex:selectList value="{!selectedwing}" size="5" multiselect="true" >
                            <apex:selectOptions value="{!ListOfwing}"/>
                        </apex:selectList>
                    </apex:OutputPanel>
                </apex:pageBlockSection>
            </apex:pageBlock>
        </apex:form> 
    </apex:page>
controller:
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.name , u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}

 
Best Answer chosen by ajith kumar 35
Newbie__SalesforceNewbie__Salesforce
Hey Ajith

Refer this code and let me know if u face any issue
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.id , u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}

 

All Answers

Newbie__SalesforceNewbie__Salesforce
Hey Ajith

Refer this code and let me know if u face any issue
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.id , u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}

 
This was selected as the best answer
Raj VakatiRaj Vakati
Change your code as below 
 
public with sharing class test {
    public list<String> selectedwing{set;get;}
    
    public List<SelectOption> getListOfwing(){
        List<Wing__c> wing = [select id,name from Wing__c] ;
        List<SelectOption> wingOptionList = new List<SelectOption>();
        for(Wing__c u : wing ){
            wingOptionList.add(new SelectOption(u.Id, u.Name));
        }
        return wingOptionList;
    }
    public test(){
        
        
    }
}