You need to sign in to do that
Don't have an account?
![Aiden Byrne Aiden Byrne](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Saving enum values in Salesforce
For selected fields I want to save the enum display type in custom settings. Its a long story but for performance reasons I don't want to requery the underyling schema for these fields every time.
A conservative approach to saving an enum would be to save it's string value. Unfortunately unlike Java, APEX doesn't appear to offer a enum.valueOf(s) type method letting me de-reference the string parameter.
I could save the ordinal. Happily, I can easily convert ordinal back to the enum via enum.values()[ordinalNumber]
The latter approach minimizes the custom settings field size and should be fast.
Here's the thing... is it safe? If Salesforce engineering inadvertantly changes the order of enum values I'm in trouble. That said, absent the ability to easily do this another way, I would hope that Saleforce engineering is careful to view the enum value order as part of the API contract - and not change the order from release to release. Is that a safe assumption?
CustomSetting.getInstance(Name)
Aiden said "Unfortunately unlike Java, APEX doesn't appear to offer a enum.valueOf(s) type method letting me de-reference the string parameter."
Actually, it does from what I can tell (perhaps it did not at the time of your post).
the "name()" method will yield the string of the enum value.
Here are more enum methods:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_enum.htm