3

If I run DescribeFieldResult.getPicklistValues(), e.g., Contact.Salutation.getDescribe().getPicklistValues(), it usually returns the PicklistEntry records for Salutation in the order that I have established in the metadata.

The order is undocumented. Is this reliable?

  • I could swear this is a duplicate... – sfdcfox Jun 27 '17 at 20:57
2

I have used this method a few times and the ordering is reliable. It will be based off of how you define the settings for the picklist field.

A link to another related question to reinforce reliability of ordering:
Get picklist values in apex in the order they were entered

1

The order is not guaranteed by the documentation. However, if the order was not guaranteed, and it ever changed for any reason whatsoever, there'd be a lot of angry clients out there. For example, consider this answer. If the order were to change, we would have no way to identify the index of a picklist value relative to other picklist values, and therefore it would break this code. Code that businesses rely on for business processes. Many others here and in other communities have advocating using this method, and there's various samples of doing so on blogs, in the documentation, and elsewhere.

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