Skip to main content
3 of 3
added 1 character in body
Keith C
  • 137.3k
  • 29
  • 218
  • 458

You can build the SelectOption objects in your controller:

public Id selectedUserId {get; set;}

public List<SelectOption> getUserSelectOptions() {
    List<SelectOption> options = new List<SelectOption>();
    for (User u : [Select Id, Name from User order by Name limit 1000]) {
        options.add(new SelectOption(u.Id, u.Name));
    }
    return options;
}

and so the Visualforce becomes:

<apex:selectList value="{!selectedUserId}" size="1">
    <apex:selectOptions value="{!userSelectOptions}"/>
</apex:selectList>

Note that the earlier version of this answer suggested using an apex:repeat to allow multiple apex:selectOption elements but as Carlos reports in his comment below Visualforce validates against that.

Keith C
  • 137.3k
  • 29
  • 218
  • 458