Sort a list of sObjects: quick and dirty -or- elegant

2 Oct

Quick and Dirty

Here is a method that I’ve implemented to sort lists of objects by combinations of fields. I don’t claim that it is pretty, but it has worked for me.

With the help of a method from my other post.


Implement the Comparable interface on a sub-class allows a list of the objects to be sorted using a familiar ‘.sort()’ method.

Now that your subclass is setup, you can use the built-in sort method for the instantiated object list.