You need to sign in to do that
Don't have an account?
Abhilash Mishra 13
getting picklist field options in list in apex classs
Hi,
can i get all the values of a picklist field in a list some how?
I have picklist type custom field in the product. having some options.
In my apex class i want to use these options. can I get them some how throught code?
can i get all the values of a picklist field in a list some how?
I have picklist type custom field in the product. having some options.
In my apex class i want to use these options. can I get them some how throught code?
If you want to display pick list values in your custom page through dyanamic apex .You can check below link it will help .
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
If you want in a string array or list then you can use below code .
Let us know if it helps !!
Thanks
Manoj
All Answers
/*
*************************************************************************************************************
* Below method is issed to get the picklist value.
*************************************************************************************************************
*/
public List<SelectOption> getProduct()
{
List<SelectOption> options = new List<SelectOption>();
Schema.DescribeFieldResult fieldResult = Contact.Product__c.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for( Schema.PicklistEntry f : ple)
{
options.add(new SelectOption(f.getLabel(), f.getValue()));
}
return options;
}
If you want to display pick list values in your custom page through dyanamic apex .You can check below link it will help .
https://developer.salesforce.com/blogs/developer-relations/2008/12/using-the-metadata-api-to-retrieve-picklist-values.html
If you want in a string array or list then you can use below code .
Let us know if it helps !!
Thanks
Manoj
Below code will work.
public static void getSessionLevels()
{
Schema.DescribeFieldResult fieldResult = Opportunity.StageName.getDescribe();
List<Schema.PicklistEntry> ple = fieldResult.getPicklistValues();
for(Schema.PicklistEntry s:ple){
System.debug('value: '+s.getLabel());
}
}
I'm guessing some of you would like a fully dynamic solution. Here's a method you can pop into a Utilities class to make life easier. I do, and my utilities class is named... wait for it... Utilities.
public class Utilities {
public static String[] picklist_values(String object_name, String field_name) {
String[] values = new String[]{};
String[] types = new String[]{object_name};
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
for(Schema.DescribeSobjectResult res : results) {
for (Schema.PicklistEntry entry : res.fields.getMap().get(field_name).getDescribe().getPicklistValues()) {
if (entry.isActive()) {values.add(entry.getValue());}
}
}
return values;
}
}
Example:
There's a custom field on Contact called Favorite_Colors__c with these active values: 'Pink', 'Orange', 'The Whole Rainbow'
System.debug(Utilities.picklist_values('Account', 'Favorite_Colors__c')) => (Pink, Orange, The Whole Rainbow)
Controller:
Visualforce page:
Khatrimaza (https://www.gorakhpurhindinews.com/khatrimaza-download-hd-movie-online-free/) Movies Wood (https://www.gorakhpurhindinews.com/movies-wood-download-movies-online/) Google Fauji (https://www.gorakhpurhindinews.com/fau-g-fauji-now-live-for-pre-registration-on-google-play-store/)
thanks sales force team
UP Ganna Parchi Calendar (https://www.gorakhpurhindinews.com/ganna-parchi-calendar/)
UP Bhulekh (https://www.gorakhpurhindinews.com/uttar-pradesh-bhulekh/)
labreports.upcovid19tracks.in (https://www.gorakhpurhindinews.com/online-labreports-upcovid19tracks-in/)
UP Online Corona Test Report (https://www.gorakhpurhindinews.com/online-covid-19-test-report-on-website-labreports-upcovid19tracks-in/)
Yogi Adityanath Mobile Number
Yogi Adityanath Email ID
PM Modi Mobile Number (https://www.gorakhpurhindinews.com/what-is-prime-minister-narendra-modi-email-id-phone-number-contact-and-address-details/)
PM Modi Email ID (https://www.gorakhpurhindinews.com/what-is-prime-minister-narendra-modi-email-id-phone-number-contact-and-address-details/)
If you want to get picklist values in apex then you can check below link it will help.
https://sfdctechsolutions.blogspot.com/2021/08/get-picklist-values-in-apex.html
Let us know if it helps !!
Thanks
Sumit
Thanks,
HWC Loan Personal