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
ashish jadhav 9ashish jadhav 9 

What is dynamic pick list?

what is the use of this picklist?
Vasani ParthVasani Parth
Ashish :

Many a times we come across situations in which we want data to be added to a picklist dynamically.By saying dynamic i mean that you do not want an Administrator to go to the field level setup and add values to the picklist. Below is the sample code for you to understand

Controller
public class TestSelectController{
    public List<SelectOption> getYears() {
        List<SelectOption> options = new List<SelectOption>();
        for (Integer i = System.Today().year() - 3; i < System.Today().year() + 3; i++) {
            options.add(new SelectOption(String.valueOf(i), String.valueOf(i)));
        }
        return options;
    }

    public String selectedYear {get; set;}

    public TestSelectController() {
        selectedYear = String.valueOf(System.Today().year());
    }
}

Page
<apex:page controller="TestSelectController">
    <apex:form>
        <apex:selectList value="{!selectedYear}" size="1">
            <apex:selectOptions value="{!Years}"/>
        </apex:selectList>
    </apex:form>
</apex:page>

This blogpost (http://www.forcetree.com/2009/06/dynamically-add-values-to-picklist.html)helps you to get detailed information for more information.

Please mark this as the best answer if this helps
 
Lee BeardshawLee Beardshaw
A dynamic picklist allows end users to add values to the list rather than requiring the assistnace of an administrator. It can be updated as and when values are required. This is particularly useful if you have processes within your organisation whereby you would have to request values to be added to a standard picklist. This could take some time and if you're in the middle of something, it would distract from what you're doing and delay things unnecessarily. This is a great post from Forcetree.com Salesforce Unearthed - Dynamically add values to picklist (http://www.forcetree.com/2009/06/dynamically-add-values-to-picklist.html). Please mark as best answer if this has resolved your query. Many thanks.
JyothsnaJyothsna (Salesforce Developers) 
Hi Ashish,

Many times we come across situations in which we want data to be added to a picklist dynamically.

By saying dynamic I mean that you do not want an Administrator to go to the field level setup and add values to the picklist...
Please check the below link for detailed description and example

http://www.forcetree.com/2009/06/dynamically-add-values-to-picklist.html

Example2:

Visualforce Page
<apex:page controller="ObjectRetrieve">
<apex:form >
<apex:outputlabel value="All Objects"/>&nbsp;&nbsp;
<apex:selectList size="1">
<apex:selectoptions value="{!objnames}"></apex:selectoptions>
</apex:selectList>
</apex:form>
</apex:page>

Controller
 
public with sharing class ObjectRetrieve {

//Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();

public List<SelectOption> getobjNames()
{
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('--None','--None--'));
for(Schema.SObjectType f : gd)
{
if(f.getDescribe().getName().contains('__c'))
options.add(new SelectOption(f.getDescribe().getName(),f.getDescribe().getName()));
}
return options;
}
}

Hope this helps you!
Best Regards,
Jyothsna