Activity Forums Salesforce® Discussions How can I select multiple options from a selectlist with preset selected values in Salesforce?

  • Mohit

    Member
    September 30, 2016 at 6:49 am

    Hi Pranav,

    You can achieve the multi select option from a select list in this way:-

    Page:-

    <apex:page controller="MultiselectController">
    <apex:form >
    <apex:selectList value="{!value}" size="3" multiselect="true" label="blah" id="blah" >
    <apex:selectOptions value="{!options}" />
    </apex:selectList>
    </apex:form>
    </apex:page>

    Controller:-

    public class MultiselectController {
    public List<SelectOption> options { get; set; }
    public String[] value { get; set; }

    public MultiselectController() {
    value = new String[] { 'a', 'b','c'};
    options = new List<SelectOption> {
    new SelectOption('a', 'a'),
    new SelectOption('b', 'b'),
    new SelectOption('c', 'c'),
    new SelectOption('d', 'd'),
    new SelectOption('e', 'e')
    };
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos