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
divya1234divya1234 

how to sort picklist value from custom settings and how to set default value

I stored all my picklis values in custom setting and i am accessing those values in my  controller like  /**for (ApplicationPicklist__c Application : ApplicationPicklist__c.getAll().values())
       options.add(new SelectOption(Application.Application__c ,Application.Name+' - '+Application.Application__c));
        return options;**/

do we have option to set any default value in apex code .and cn i sort the values alphabetically
Khan AnasKhan Anas (Salesforce Developers) 
Hi Divya,

Greetings to you!

Please try the below code:
 
List<ApplicationPicklist__c> ap=ApplicationPicklist__c.getAll().values();
ap.sort();

for (ApplicationPicklist__c Application : ap) {
       options.add(new SelectOption(Application.Application__c ,Application.Name+' - '+Application.Application__c));
}

return options;

Please refer to the below link which might help you further.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas