-
Notifications
You must be signed in to change notification settings - Fork 519
ListSortingRecipes
codefriar edited this page Oct 6, 2021
·
10 revisions
Demonstrates how to sort lists with custom ordering logic
ListUtils, SortableAccount, SObjectStringFieldComparator
Demonstrates how to sort a list of SObject in place with reusable comparators. This example shows how to sort Accounts based on the ShippingCountry field. We use a generic ListUtils utility class with a SObjectStringFieldComparator class that implements the ListUtils.Comparator interface.
| Param | Description |
|---|---|
accounts |
a list of accounts that will be sorted in place |
Demonstrates how to sort a list of SObject in place (without the need for a return statement). This example shows how to sort Accounts based on the ShippingCountry field. We use a SortableAccount wrapper class in order to implement the Comparable interface so that we can use List.sort() with SObject.
| Param | Description |
|---|---|
accounts |
a list of accounts that will be sorted in place |