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
jamesclark clarkjamesclark clark 

how to create a drop down field for year

Hi everyone,
I'm new to salesforce i don't know can we create a drop down field for the Years. I tried to create using apex method but i was not.

Can anyone help me over here.

Thanks in advance.
Where do you want to create this field? On any object or a vf page?
jamesclark clarkjamesclark clark
In vfpage.
jamesclark clarkjamesclark clark
I want to show the values through code not by manually. Can we.........?
There are vf tags called <apex:selectList> and <apex:selectOption>, you can use them to show a drop down.
public List<selectOption>      selectOptions        {get;set;}
public string                  selectedOption {get;set;}
public void loadSelectOptions() {
   selectOptions = New List<selectOption>();                
   selectOptions.add( new selectOption('', 'Choose one'));
   selectOptions.add( new selectOption('Option1','Option #1 Description'));
   selectOptions.add( new selectOption('Option2',' Option #2 Description '));
   selectOptions.add( new selectOption('Option3',' Option #3 Description '));
<apex:pageBlockSectionItem >
   <apex:outputLabel value="Select Option" />
          <apex:selectList value="{!selectedOption}" size="1" >
                 <apex:selectOptions value="{!selectOptions}"/>
// In other code….
IF (selectedOption == ‘Option1’) {
   // Do Option1 stuff
} ELSE IF (selectedOption == ‘Option2’) {
   // Do Option2 stuff
} ELSE {
   // Do Option3 stuff