Home > Apex-Select-Option-Sorting

Apex-Select-Option-Sorting

Apex-Select-Option-Sorting is a project mainly written in ..., it's free.

Salesforce APEX API to Sort Array/List of SelectOption instances

This repository provides a Utility class to provide efficient sorting of Apex SelectOption instances. Efficient as all the heavy lifting of sorting is internally handled by native List.sort(), so this leads to fast sorting and lesser consumption of script statements and one is more safe from Governor.

Example Usage

Sort by Label :

Selectoption[] opts = new Selectoption[] { new Selectoption('v8', 'l8'), new Selectoption('v1', 'l1'), new Selectoption('v5', 'l5') };

SelectOptionSorter.doSort(opts, SelectOptionSorter.FieldToSort.Label); // This will print the sorted list System.debug (' Sorted Options : ' + opts);

// // Following will be output on console //

|DEBUG| Sorted Options : (System.SelectOption[value="l1", label="v1", disabled="false"], System.SelectOption[value="l5", label="v5", disabled="false"], System.SelectOption[value="l8", label="v8", disabled="false"])

Sort by Value :

// Just pass SelectOptionSorter.FieldToSort as "SelectOptionSorter.FieldToSort.Value" // instead of "SelectOptionSorter.FieldToSort.Label" SelectOptionSorter.doSort(opts, SelectOptionSorter.FieldToSort.Value);

Previous:zantastico