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
Emmanuel CoronaEmmanuel Corona 

Custom Multi Select Picklist

Greetings!

 

I'll really appreciate your help if you can help me on how i can build a custom multi select picklist and for values, the name (records) from my custom object for example:

 

Object A

Name: test1

Name: test2

to N

 

The Multi Select Picklist values= test1, test2, to N

 

And add it for use it in my my opportunity page

 

Thank you !

Bhawani SharmaBhawani Sharma
You need to create a List of SelectOption and bind that on Page.

List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('test1', 'test1'));
options.add(new SelectOption('test2', 'test2'));
options.add(new SelectOption('testN', 'testN'));

On Page,
<apex:selectionList multiselect="true">
<apex:selectOptions ="{!options}" />
</apex:selectList>
Karthikeyan JayabalKarthikeyan Jayabal

Below sample code accomplishes the same functionality.

Here Category__c is the custom object & the multi-select picklist displays the Name field of that object.

You can change the query to fit the actual requirement.

 

PAGE:

<apex:page standardController="Opportunity" extensions="extension_customPicklistDemo">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection columns="1">
                <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Category"/>
                    <apex:selectList value={!selectedCategories}>
                        <apex:selectOptions value="{!categories}"/>
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 CONTROLLER:

public with sharing class extension_customPicklistDemo {
    public List<String> selectedCategories { get; set; }
    
    public extension_customPicklistDemo(ApexPages.StandardController controller) { }
    
    public List<SelectOption> getCategories() {
       List<SelectOption> categories = new List<SelectOption>();
       for(Category__c c : [Select Name from Category__c limit 10])
           categories.add(new SelectOption(c.Name, c.Name));
       return categories;
    }
}

 

 

 

Emmanuel CoronaEmmanuel Corona
Thank you Bhawani! let me try to do that
Emmanuel CoronaEmmanuel Corona
hello Karthikeyan just one question "limit 10" here i can change it maybe to display more tan 2000 records????
Emmanuel CoronaEmmanuel Corona

 

Emmanuel CoronaEmmanuel Corona
Hello again Bhawani! well maybe i don't explain well... what i'm trying to do is a multiselect picklist, the values will be the records from a custom object (the name) and i want to add it in to the opp page so when the user register a new entry, can select all the items that they want and saved into the opp :)