Find your content:

Search form

You are here

Setting Default picklist value on loading of Visualforce page

 
Share

I have designed a VF page to create a new record in which I am trying to display the value of a pick-list field. I have set a default value for this pick-list field. When trying to create the record using the salesforce native page, the value with which pick-list loads is the one I set as default but when creating the same record using VF page, the pick-list loads with "--None--" as default value.

Can anyone suggest If this is salesforce related bug or Am I doing anything wrong ?


Attribution to: ShankarSharma

Possible Suggestion/Solution #1

As of Winter '14, if this was a bug it appears to have been fixed. The following code displays the default value for the picklist field.

<apex:page standardController="Custom_Object__c">
  <apex:form>
    <apex:inputField value="{!Custom_Object__c.Picklist__c}"/>
  </apex:form>
</apex:page>

Attribution to: Ralph Callaway

Possible Suggestion/Solution #2

If you have any record types associated with the object, you'll need to select the default picklist value for those record types as well. That should solve your issue. If it doesn't, make sure your controller class is set to "with sharing" as that also may have an impact on the default value display.


Attribution to: James Loghry

Possible Suggestion/Solution #3

public class sam{
    public string str {get; set;}
    public List<SelectOption> lstPicks {get; set;}

    public sampleCon(){
        str = 'Two';
    }
    public List<SelectOption> getPicks() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('One','One'));
        options.add(new SelectOption('Two','Two'));
        options.add(new SelectOption('Three','Three'));
        return options;
    }   
}

Attribution to: Jayanth Thathapudi

Possible Suggestion/Solution #4

Maybe this is an option to work around your problems: Use a link or button to call your Visualforce page and add the field id and the default value to the page's URL as described here: http://raydehler.com/cloud/clod/salesforce-url-hacking-to-prepopulate-fields-on-a-standard-page-layout.html

e. g. /visualforcepageurl?fieldId=DefaultValue


Attribution to: georg w.
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1522

My Block Status

My Block Content