You need to sign in to do that
Don't have an account?
prakashedl
Sorting Custom Settings
I created a custom setting say Department. It consists of a depeartment code and department name. Through manage link i created multiple instances to represent departments in my organization. Now when I retrieve all the values in this Custom setting using getAll.Values() , I would like to have them in a particular sorted order. Is there an efficient or a recommended way to sort values in custom settings? Please advice
Here's a way to sort the settings:
Map<String, Setting__c> settings = Setting__c.getAll();
List<String> settingNames = new List<String>();
settingNames.addAll(settings.keySet());
settingNames.sort();
//now if you can for example create SelectOptions
for (String s : settingNames) {
Setting__c stg = settings.get(s);
options.add(new SelectOption(stg.Code__c, stg.Name));
}