function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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>();

//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));