I want to get the picklist values of a picklist field in Apex.

I use the someFieldResult.getPicklistValues(); function and that works fine. This gives me all the picklist values, in alphabetic order (e.g. Alpha, Beta, Gamma).

However, I want to have those values in the order they were entered (e.g. Gamma, Alpha, Beta). How to do that?


The DescribeFieldResult.getPickListValues method returns the values in their currently defined order. If you sort then after you have entered them by e.g. checking the:

Sort values alphabetically, not in the order entered. Values will be displayed alphabetically everywhere.

checkbox then that sorted order will be the only one available to you from the platform.

But you can go back and manually reorder the values. I suggest you do that via the "Reorder" button displayed for the "Picklist Values" of a picklist field.

  • Now that I debug the list, yes, this seems to be the case. I was confused because the order is again messed up when I show the List of options in Visualforce: they always show in alphabetic order. Is there something I can do about that? – Willem Mulder May 18 '15 at 6:26
  • 2
    Oh well, nevermind. I used a map, and that never works for sorting. Now I use the original List and all is fine! Thanks. – Willem Mulder May 18 '15 at 6:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.