So this is i donw so far, In this pick list there is two value like active,new. I want to set this both option as pre select by default.

Visua force page

        <td style="font-weight:bold;">Property Status<br/>

<apex:selectList id="status" size="8" style=" max-height: 250px !important;overflow-y: scroll !important;"  multiselect="true" value="{!test7}" onchange="updatebnk7(this.value)"   >
        <apex:selectOption itemValue="no" itemLabel=" "/>
        <apex:selectOptions value="{!status}"  />
         <apex:actionSupport event="onchange" reRender="results" />
<apex:actionFunction name="updte7" action="{!check7}">
                   <apex:param assignTo="{!test7}" value="val" name="current"/>

Apex controller

public list<SelectOption> status{
    get {

        Schema.DescribeFieldResult field = REOHQ__REOHQ_Property__c.REOHQ__REOHQ_Property_Status__c.getDescribe();

              List<Schema.PicklistEntry> ple = field.getPicklistValues();

        for( Schema.PicklistEntry f : ple){

        if(n != 1){

          optn4.add(new selectOption(f.getValue(),f.getLabel()));

      return optn4;          
  • Is updatebnk7 a method in your controller? You have this set for a multi-select list, yet one value is "Active" and the other is "Deactive". Can you actually have "both" conditions at the same time without a conflict? Off-hand, that doesn't seem wise or appropriate considering the values. In general though, the answer would be to set them in your controller extension or custom controller that you're using.
    – crmprogdev
    Apr 5, 2016 at 16:45
  • please take a look at updated code Apr 5, 2016 at 17:03

2 Answers 2


Edited based on Question edit

Since you're describing a picklist in a getter, you cannot reliably pre-populate the values in your list. Also, your code is (possibly) buggy because it may cause the opt4 list to grow each time the getter is called. Instead, consider populating this value just the first time:

public list<SelectOption> status{
    get {
        if(optn4 == null) {
            opt4n = new List<SelectOption>();
            for( Schema.PicklistEntry f : REOHQ__REOHQ_Property__c
                optn4.add(new selectOption(f.getValue(),f.getLabel()));
        return optn4;

At this point, though, you'd still need to iterate over the values initially in your constructor:

public MyController() {
    test4 = new List<String>();
    for(SelectOption option: status) {
    // More code here

Don't use an actionFunction this way, because you're just asking for trouble. First of all, "value" won't be populated the way you expect, because it's a multi-select picklist. Secondly, the values in test7 will automatically be written back into the value any time you perform an action; bindings are two-way by default when using an input element of any type.

  • check updated code, Hope it make sense Apr 5, 2016 at 17:02
  • @Salesfor_dev I've updated my answer for you.
    – sfdcfox
    Apr 5, 2016 at 17:17
  • I this where you have declare "Active" and "New" picklist value to pre select by default? Apr 5, 2016 at 17:47

What you've posted is the code that generates your select option list for status. OnChange, you call an ActionFunction in your JS or Controller for check7 that sends the selected values to that method. What does that method look like? More importantly, someplace in your constructor, there's code that calls your status method.

Once your select options have been returned to your constructor, you could call another method that would look something like this:

 public list<string>selectedStatuses;

 public list<string> SetselectedStatuses(list<SelectOption> status) {

        selectedStatus = new list<string>();
        for (SelectOption selOption : status)

            if (selOption.getValue() == 'active' || 'new')



        // set selectedStatuses;
        return selectedStatuses;

The return sets the selectedStatuses to the defaults in the values you've set.

Later, use a similar method to determine what's been selected using a getSelectedstatus method where you iterate on the SelectOptions. Compare the results with what's in selectedStatuses (your default values). If they're different, use the new results. If they're not, use the default values.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .