You need to sign in to do that
Don't have an account?

How to sort custom list in apex
I have a picklist defined in vf page and I have created a custom setting (Countries__c ) which has a field CountryCode__c .
so its like this
Australia CA
India IN
America USA
when the visual force page loads I want the picklist values to be sorted but it is not happening.
Thanks
John
so its like this
Australia CA
India IN
America USA
when the visual force page loads I want the picklist values to be sorted but it is not happening.
public class someclass { private List<SelectOption> countryCodeList = new List<SelectOption>(); //Holds the Country Code for the selected option public String selectedCountryCode {get; set;} } public List<SelectOption> getCountryCodes() { if(countryCodeList.isEmpty()) { for(Countries__c country :Countries__c.getAll().values()) { countryCodeList.add(new SelectOption(country.CountryCode__c, country.Name)); } } countryCodeList.sort(); //doesnt work return countryCodeList; }Please help me out.
Thanks
John
Try with below code !!
Let me know if it helps!!
Thanks
Manoj
I am getting an error as Loop must iterate over a collection type:
Thanks
John
Try with below code it will work !!
Let me know if it helps !!
Thanks
Manoj