+ Start a Discussion
rishi jaykar 1rishi jaykar 1 

I was able to use the standard controller in VF page to get the picklist field, but how can i use the controller to get the picklist field? please help

this is the code for standard controller = "Forecast__c" to get the field Picklist1__c
<div class="slds-form-element__control">
<div class="slds-select_container">
<apex:inputField value="{!Forecast__c.Picklist1__c}" styleClass="slds-select slds-input slds-input--small" />
</div>
</div>
Best Answer chosen by rishi jaykar 1
David HalesDavid Hales
Hi
You need to use getDescribe() method to get picklist information and then use getPicklistValues to get picklist data and then use selectOptions to create your custom picklist
Schema.DescribeFieldResult fieldResult =
OfficeLocation__c.Country__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}

If the above suggestion worked, let us know by marking the answer as "Best Answer" right under the comment which will help the rest of the community should they have a similar issue in the future. 

Thanks & Regards 
David Hales(1044)
Kloudrac Software Pvt. Ltd.

All Answers

David HalesDavid Hales
Hi
You need to use getDescribe() method to get picklist information and then use getPicklistValues to get picklist data and then use selectOptions to create your custom picklist
Schema.DescribeFieldResult fieldResult =
OfficeLocation__c.Country__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();

for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}

If the above suggestion worked, let us know by marking the answer as "Best Answer" right under the comment which will help the rest of the community should they have a similar issue in the future. 

Thanks & Regards 
David Hales(1044)
Kloudrac Software Pvt. Ltd.
This was selected as the best answer
PawanKumarPawanKumar
Hi Rishi,

Please refer below link withexample for better undestanding

https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html

https://developer.salesforce.com/forums/?id=906F000000090GdIAI

https://salesforce.stackexchange.com/questions/4992/how-to-get-a-picklist-all-values-in-apex-controller

Regards,
Pawan Kumar

PS: Please let me know if it helps you.