Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
Hi,
I would like to know how to fetch default piclist values of a field in apex class.
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.
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
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
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
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.