function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to create a picklist of custom object records?

I'm building a custom UI, and I need to be able to select records using a picklist. This generated automatically in the Console view, but I'm trying to figure out how to add a similar feature to a custom Visualforce UI.


For example, we have a custom object named "Records", and we want to create a dropdown menu in our UI that allows the user to select a record from the list of all records for this object.


Also, is it possible to see the Visualforce source code behind the Console view? That would help a lot.



Shailesh DeshpandeShailesh Deshpande

This Is something that i tried out....I hope this works for you...In your Case it will be Record__c object... of course this will just show you how to create a dropdown will have to implement your business logic...


apex class:



public with sharing class selectoptions
    public List<opportunity> lst
    public selectoptions(ApexPages.StandardsetController ctlr)
        lst = [select Name from Opportunity];
    public List<SelectOption> getItems()
        List<SelectOption> options = new List<SelectOption>();
        for(Integer i=0; i < lst.size(); i++)
            options.add(new SelectOption(lst[i].Name,lst[i].Name));
        return options;



VF Page:


<apex:page standardController="opportunity" recordsetVar="rec" extensions="selectoptions">
<apex:form >
<apex:outputLabel style="font-weight:Bold" value="Select an Opportunity :" />
<apex:SelectList size="1" value="{!lst}">
<apex:selectOptions value="{!items}"/>



i hope this helps..



The above code is one of the examples this type method wan't work in some situations


1.Create an object

2.Add  a picklist fields to the object

3.get picklist values from the object using an Controller

4.Display the picklist values in the UI.


For code sample search developer force lot samples is there.