I have a simple page with a form that is supposed to create a custom object. This custom object has several picklist fields. I can dynamically populate the selectLists, but when I give the selectList the object's picklist value, it disappears from the page.

What I have on the page:

<apex:selectList value="{!sa.Machine__c}" multiselect="false" label="Machine" size="1">
    <apex:selectOptions value="{!machineOptions}"/>

In my controller:

public Change__c sa { get; set; }

public Controller() {
    sa = new Change__c();

private void prePopulateOptions() {
    machineOptions = populateOptions(Change__c.Machine__c.getDescribe());

private List<SelectOption> populateOptions(Schema.DescribeFieldResult fieldDescription) {
    List<SelectOption> options = new List<SelectOption>();

    // For each picklist value, create a new select option
    for (Schema.Picklistentry picklistEntry: fieldDescription.getPicklistValues()){
        options.add(new SelectOption(pickListEntry.getValue(),pickListEntry.getLabel()));
    return options;

If I remove the selectList value, or change the value to a String object, it shows the selectList on the page. But it does not now.

Ultimately, I just want a convenient way to upsert the sa object.

1 Answer 1


It looks like you are simply adding the values from the field schema to selectOption without modification and showing in the page. In that case, if you use simply input field as below it will give same result,

<apex:inputField value="{!sa.Machine__c}"/>

This will not require you to set the selected value to object explicitly. If there is some other reason and you want it to be selectOption list, you can set the selected value to a string property in controller and in the save method, you can overwrite the Machine__c field value with the string property value.

  • It took me a while to figure out what you meant, but you are correct. It is easier to use the inputField directly than setting up the list myself. And it is good enough for my purposes. The reason I couldn't view the fields was (obviously) not related to all of this directly, but rather because the field-level security wasn't set to visible.
    – Oxidator
    Apr 15, 2015 at 3:45

You must log in to answer this question.

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