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
GirinoobGirinoob 

How to fetch piclist values of a field

Hi,

I would like to know how to fetch default piclist values of a field in apex class.

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

for(Schema.PicklistEntry P : Account.Industry.getDescribe().getPicklistValues())
{
    if(P.isDefaultValue())
        system.debug('==================  ' + P.getValue());    
}

 

 

This would give you the default Picklist value for Account's Industry field. Modify and use the code as per your requirement.

All Answers

PrakashbPrakashb

You can get the picklist values using the describe method. Please see the link below. http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm

vishal@forcevishal@force

for(Schema.PicklistEntry P : Account.Industry.getDescribe().getPicklistValues())
{
    if(P.isDefaultValue())
        system.debug('==================  ' + P.getValue());    
}

 

 

This would give you the default Picklist value for Account's Industry field. Modify and use the code as per your requirement.

This was selected as the best answer