+ Start a Discussion
sagar@sfdcsagar@sfdc 

how to store selectlist values of visualforce page into a local variable or list in apex class

how to store the multiple values selected in selectlist  for local variable or list in apex controller  this is the code

 

<apex:selectList styleclass="textboxreddrop" size="4" multiselect="true"
                                id="Activities" value="{!activity}">
                                <apex:selectOptions value="{!SOption2s}" />
                            </apex:selectList>

 

controller///////////

public String activity{get;set;}

public List<SelectOption> getSOption2s()
    {
        List<SelectOption> options = new List<SelectOption>();
      
        //options.add(new SelectOption('None','--None--'));        
        Schema.DescribeFieldResult fieldResult = ACT_Interest__c.ORG_CSI_Tags__c.getDescribe();
        List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
        for(Schema.PicklistEntry p : ple)
        options.add(new SelectOption(p.getValue(), p.getValue()));
         
        return options;
    }

 

JHayes SDJHayes SD

The docs for apex:selectList:  http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_selectList.htm

 

Your mutiselect attribute is set to true so your activity property needs to be an array of Strings.  In the docs they list is as private and add accessor methods so you would replace your property with something like this:

 

String[] activity = new String[](); 

public String[] getActivity() {
  return activity;
}

public void setActivity(String[] activity) {
  this.activity = activity;
}