I'm trying to display all custom object records in multi-select picklist,I'm able to displaying fields of custom object but how can I display all records instead of fields.

This is my apex class:

public class DynamicCustomizableListHandler {

    // Resources we need to hold on to across requests
    private ApexPages.StandardSetController controller;
    private PageReference savePage;
    private Set<String> unSelectedNames = new Set<String>();
    private Set<String> selectedNames = new Set<String>();
    private Set<String> inaccessibleNames = new Set<String>();

    public DynamicCustomizableListHandler(ApexPages.StandardSetController controller) {
        this.controller = controller;
    // Initial load of the fields lists
    private void loadFieldsWithVisibility() {
        Map<String, Schema.SobjectField> fields = 
        for (String s : fields.keySet()) {
            if (s != 'Name') {  // name is always displayed 
            if (!fields.get(s).getDescribe().isAccessible()) {
    public List<String> getDisplayFields() { 
        List<String> displayFields = new List<String>(selectedNames);
        return displayFields;
    public PageReference customize() {
        savePage = ApexPages.currentPage();
        return Page.CustomizeDynamicList;
    public PageReference show() {
        // This forces a re-query with the new fields list
        return savePage; 

    // Create the select options for the two select lists on the page
    public List<SelectOption> getSelectedOptions() { 
        return selectOptionsFromSet(selectedNames);
    public List<SelectOption> getUnSelectedOptions() { 
        return selectOptionsFromSet(unSelectedNames);

    private List<SelectOption> selectOptionsFromSet(Set<String> opts) {
        List<String> optionsList = new List<String>(opts);
        List<SelectOption> options = new List<SelectOption>();
        for (String s : optionsList) {
                SelectOption(s, decorateName(s), inaccessibleNames.contains(s)));
        return options;

    private String decorateName(String s) {
        return inaccessibleNames.contains(s) ? '*' + s : s;

    public transient List<String> selected   { get; set; }
    public transient List<String> unselected { get; set; }

    public void doAdd() {
        moveFields(selected, selectedNames, unSelectedNames);
    public void doRemove() {
        moveFields(unselected, unSelectedNames, selectedNames);

    private void moveFields(List<String> items, 
            Set<String> moveTo, Set<String> removeFrom) {
        for (String s: items) {
            if( ! inaccessibleNames.contains(s)) {

This is my page:

 <apex:page standardController="LightiningEd__Webinar_Attendees_Status__c" recordSetVar="ignored" extensions="DynamicCustomizableListHandler">
    <apex:form >
    <apex:pageBlock title="Select Users For Meeting" id="selectionBlock">
        <apex:pageMessages />
        <apex:panelGrid columns="3">
            <apex:selectList id="unselected_list" required="false" 
                value="{!selected}" multiselect="true" size="20" style="width:250px">
                <apex:selectOptions value="{!unSelectedOptions}"/>
            <apex:panelGroup >
                <apex:commandButton value=">>" 
                    action="{!doAdd}" rerender="selectionBlock"/>
                <apex:commandButton value="<<" 
                    action="{!doRemove}" rerender="selectionBlock"/>
            <apex:selectList id="selected_list" required="false" 
                value="{!unselected}" multiselect="true" size="20" style="width:250px">
                <apex:selectOptions value="{!selectedOptions}"/>
        <em>Note: Fields marked <strong>*</strong> are inaccessible to your account</em>
    <apex:commandButton value="Show These Fields" action="{!show}"/>

If you want to use data instead of metadata, you have to query for it.

unselected = new Set<String>();
for (MyObject__c record : [SELECT Name FROM MyObject__c])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy