Activity Forums Salesforce® Discussions How can I create custom picklist on a Salesforce Visualforce Page? Reply To: How can I create custom picklist on a Salesforce Visualforce Page?

  • PRANAV

    Member
    March 23, 2018 at 11:04 am

    Hi Ankit,

    VF Page

    <apex:page tabStyle="Case" controller="customPicklist">
    <apex:form >
    <apex:pageBlock title="Custom PickList Demo" id="out">
    <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}" rerender="out" status="actStatusId"/>
    <apex:actionStatus id="actStatusId">
    <apex:facet name="start">
    <img src="/img/loading.gif" />
    </apex:facet>
    </apex:actionStatus>
    </apex:pageBlockButtons>
    <apex:pageBlockSection title="Custom Picklist Using selectList and selectOptions">
    <apex:selectList value="{!selectedCountry2}" multiselect="false" size="1">
    <apex:selectOptions value="{!countriesOptions}"/>
    </apex:selectList>
    <apex:outputText value="{!selectedCountry2}" label="You have selected:"/>
    </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock >

    </apex:pageBlock>
    </apex:form>
    </apex:page>

    -------------------------------------------------------------

    Apex Controller Class

    public with sharing class customPicklist {
    public String selectedCountry2{get;set;}
    public List<String> selectedCategories { get; set; }

    public List<SelectOption> getCountriesOptions() {
    List<SelectOption> countryOptions = new List<SelectOption>();
    countryOptions.add(new SelectOption('','-None-'));
    countryOptions.add(new SelectOption('INDIA','India'));
    countryOptions.add(new SelectOption('USA','USA'));
    countryOptions.add(new SelectOption('United Kingdom','UK'));
    countryOptions.add(new SelectOption('Germany','Germany'));
    countryOptions.add(new SelectOption('Ireland','Ireland'));

    return countryOptions;
    }

     

    public List<SelectOption> getCategories() {

    List<SelectOption> categories = new List<SelectOption>();

    for(Case c : [Select sahi__MultiSelectPicklist__c from Case limit 10])

    categories.add(new SelectOption(c.sahi__MultiSelectPicklist__c, c.sahi__MultiSelectPicklist__c));

    return categories;

    }
    public PageReference save(){
    return null;
    }

    }

    Hope this helps you.