You need to sign in to do that
Don't have an account?
adampro
Sorting List of SelectOptions
Hi,
I'm populating a list of all of the different objects in a respective org and returning those names to a selectList. When I retrieve the list of all the objects, they are in a random, non-alphabetical order so when they appear on the VFP it's hard to find what you're looking for. I want to sort the list of SelectOptions in alphabetical order but I can't use the sort() method on the list because it doesn't support SelectOptions.
Is there some kind of function for organizing a list of SelectOptions?
If you can't use ORDER BY clause on your SOQL, you can do the following:
1. Build a List<String> and put the Names in that list. Sort this list.
2. Build a Map<String,SelectOption> using Name as the key and place SelectOption as value.
3. Instantiate a new List<SelectOption> which will be your sorted list.
4. Iterate over the list from step 1, pulling in the SelectOption from step 2, and place each one in the new list from step 3.
Following that process should give you sorted List<SelectOption> without too much pain.
Here is an example of the technique mentioned above: http://shailendradiary.blogspot.com/2011/01/custom-sorting-of-list-collections-in.html