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
sanshasansha 

Assign default value to an inputfield of type picklist

I have an inputfield of type picklist. The picklist has the following values:
Cancelled
Draft
Pending
Completed
OnHold
 
I need to select one of the values(e.g. Draft) as the default value whenever the new page is opened.
 
I tried marking Draft option as the default value in Picklist values. However it does not work.
 
Please suggest.
jwetzlerjwetzler
default picklist values do not yet work with Visualfroce.  However you can, in your constructor of your controller, set the field value to Draft and the page will load up with that value selected.
sanshasansha
Thanks Jill.
 
I have set the default value in the constructor and it works.
FreeFree

Hi,

I'm having the same issue but am using an extension controller.

Is there a simple way to do this ?

Could you please advise how ?

 

Thanks in advance

JasonGablerJasonGabler

This "idea" is still "under consideration".   Wow.  This is clearly a bug.

Vishal_ThoriyaVishal_Thoriya

hey sansha can you tell me how to load the page with some values in pick list?

 

i know that i have to write my code in constructor of that controller?

 

but please show me a demo so that everybody can understand.

 

this question is still unsolved in community.........

 

learn and contribute..

 

thanks in advance.....

Vishal_ThoriyaVishal_Thoriya

plaese show a demo code so other newbies of  salesforce can understand that how to load the page with some value of picklist...

 

any kind of help will be appriciated...

RubyRuby

Hey Sansha,

Could you please share the code that you have written to set the default value of your picklist in the constructor?

 

Thanks..

Rakesh KumarRakesh Kumar

Hi All,

 

 

I tried to set default value Dynamically but it is not working. Temporary i used to set default picklist value manually and its working fine.

 

But my objective is to set default value dynamically.

 

Below is my apex code

 


Schema.DescribeFieldResult F = Account.Industry.getDescribe();

List<Schema.PicklistEntry> picklist = F.getPicklistValues();

String defPickListVal = null;
for (Schema.PicklistEntry pv: picklist) {
        System.debug('*******'+pv.getValue()+'??????????'+pv.isDefaultValue()); // here i can see pick list value but isDefault is returning all False
    if (pv.isDefaultValue()) {
        defPickListVal = pv.getValue();
    }
}

system.debug('Def Pick Val : ' + defPickListVal);

 

Is there another way that we can set picklist value dynamically?

 

Thanks

R.K

U JayU Jay
I have an inputfield of type picklist. The picklist has the following values:
Cancelled
Draft
Pending
Completed
OnHold
But i want to set a defult value "Select an option".
How Can i impliment it?
Rakesh KumarRakesh Kumar

there are two ways

 

1. you can add a pick list value as "Select a Option" to the pick list values. After add you make it as default by editing field.

2. Another Salesforce is always provoide you first pick list value as "Select" so no need to add extra because first value of Pick list is always Null.

 

I hope above answer will satisfy your requirement.

 

Rakesh

U JayU Jay

Thank you for your immediate reply...But actually i wanted is a picklist with values 'a','b','c','d' .But when load the page want to see 'x' instead of 'none'