+ Start a Discussion
Rung41Rung41 

Apex Select List not showing any values

I am trying to create an apex:selectList but I am getting stumped. I think the issue resides in my controller extension. I am not a developer by any means so I am not sure what I am doing wrong.  The apex list is intended to be a multi select.
 
<apex:page standardController="Task" extensions="LogACallControllerExtension,NextStep" docType="html-5.0" showHeader="false" standardStylesheets="false">

<apex:form >     
<div class="app-content"> 
<header>
<h1>Log A Call</h1><br /><br />
</header>

<section class="border-bottom">
<div class="content">   
 <label>Next Steps</label><br />
 <apex:selectList id="NextStep" styleclass="sf1input" multiselect="true" value="{!Task.Next_Steps__c}" size="1" />
<apex:selectOptions value="{!NextStepOptions}"/>
  </div>
 </section

<section class="data-capture-buttons one-buttons">
<div class="content"><apex:commandButton value="Save" action="{!save}" /><br />
</div>
</section>
</div>
</apex:form>
</apex:page>

**---ControllerExt--** 

public with sharing class NextStep {

    public NextStep() {

    }


    public NextStep(ApexPages.StandardController controller) {

    }

        String[] NextSteps = new String[]{};
         public PageReference test() {
            return null;
        }
            
        public Task task {get; set;}
            
        public List<SelectOption> getNextStepOptions() {
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('Op1','Op1'));
            options.add(new SelectOption('Op2','Op2'));
            options.add(new SelectOption('Op3',Op3));
             options.add(new SelectOption('Op4','Op4'));
             
            return options;
        }
            
        public String[] getNextSteps() {
            return NextSteps;
        }
            
        public void setNextSteps(String[] NextSteps) {
            this.NextSteps = NextSteps;
        }
    }

 
Best Answer chosen by Rung41
Sunil MadanaSunil Madana
Hi, below is the code

VF-Page:
Since you mentioned multiselect="true", it shows multi-select all the time.
<apex:page standardController="Task" extensions="LogACallControllerExtension,NextStep" docType="html-5.0" showHeader="false" standardStylesheets="false">
    <apex:form >     
        <div class="app-content"> 
            <header>
                <h1>Log A Call</h1><br /><br />
            </header>
            <section class="border-bottom">
                <div class="content">   
                    <label>Next Steps</label><br />
                    <apex:selectList id="NextStep" styleclass="sf1input" multiselect="false" value="{!Task.Next_Steps__c}">
                        <apex:selectOptions value="{!NextStepOptions}"/>
                    </apex:selectList>
                </div>
            </section>
            <section class="data-capture-buttons one-buttons">
                <div class="content"><apex:commandButton value="Save" action="{!save}" /><br /></div>
            </section>
        </div>
    </apex:form>
</apex:page>

Apex-Class:
In this class, you had missed single-quotes for "Op3".
public with sharing class NextStep {

    public NextStep() { }
    public NextStep(ApexPages.StandardController controller) { }

    String[] NextSteps = new String[]{};
     public PageReference test() {
        return null;
    }
            
    public Task task {get; set;}
        
    public List<SelectOption> getNextStepOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Op1','Op1'));
        options.add(new SelectOption('Op2','Op2'));
        options.add(new SelectOption('Op3','Op3'));
        options.add(new SelectOption('Op4','Op4'));         
        return options;
    }
            
    public String[] getNextSteps() {
        return NextSteps;
    }
        
    public void setNextSteps(String[] NextSteps) {
        this.NextSteps = NextSteps;
    }
}
If the above suggestion(s) worked, let us know by marking the answer as "Best Answer" right under the comment which will help the rest of the community should they have a similar issue in the future.
Thanks, Sunil

All Answers

Sunil MadanaSunil Madana
Hi, below is the code

VF-Page:
Since you mentioned multiselect="true", it shows multi-select all the time.
<apex:page standardController="Task" extensions="LogACallControllerExtension,NextStep" docType="html-5.0" showHeader="false" standardStylesheets="false">
    <apex:form >     
        <div class="app-content"> 
            <header>
                <h1>Log A Call</h1><br /><br />
            </header>
            <section class="border-bottom">
                <div class="content">   
                    <label>Next Steps</label><br />
                    <apex:selectList id="NextStep" styleclass="sf1input" multiselect="false" value="{!Task.Next_Steps__c}">
                        <apex:selectOptions value="{!NextStepOptions}"/>
                    </apex:selectList>
                </div>
            </section>
            <section class="data-capture-buttons one-buttons">
                <div class="content"><apex:commandButton value="Save" action="{!save}" /><br /></div>
            </section>
        </div>
    </apex:form>
</apex:page>

Apex-Class:
In this class, you had missed single-quotes for "Op3".
public with sharing class NextStep {

    public NextStep() { }
    public NextStep(ApexPages.StandardController controller) { }

    String[] NextSteps = new String[]{};
     public PageReference test() {
        return null;
    }
            
    public Task task {get; set;}
        
    public List<SelectOption> getNextStepOptions() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Op1','Op1'));
        options.add(new SelectOption('Op2','Op2'));
        options.add(new SelectOption('Op3','Op3'));
        options.add(new SelectOption('Op4','Op4'));         
        return options;
    }
            
    public String[] getNextSteps() {
        return NextSteps;
    }
        
    public void setNextSteps(String[] NextSteps) {
        this.NextSteps = NextSteps;
    }
}
If the above suggestion(s) worked, let us know by marking the answer as "Best Answer" right under the comment which will help the rest of the community should they have a similar issue in the future.
Thanks, Sunil
This was selected as the best answer
Rung41Rung41
Thank you for the quick response and pointing out my errors. Two questions though.
  1. How come I can only select one value even though I set multiselect="true" ?
  2. How come it returns the value selected with brackets around it? [Op2] ?
Select List
Returned Value