Skip to content

Instantly share code, notes, and snippets.

@Nahumancer
Last active April 21, 2019 20:33
Show Gist options
  • Save Nahumancer/69c03bbaf45c5c86090a2c70b1cee845 to your computer and use it in GitHub Desktop.
Save Nahumancer/69c03bbaf45c5c86090a2c70b1cee845 to your computer and use it in GitHub Desktop.
Get picklist valid values.
public static String[] getValidPicklistValues(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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment