Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Comparable Interface
Namespace
Usage
To add List sorting support for your Apex class, you must implement the Comparable interface with its compareTo method in your class.
The implemented method must be declared as global or public.
Comparable Methods
The following are methods for Comparable.
compareTo(objectToCompareTo)
Signature
public Integer compareTo(Object objectToCompareTo)
Parameters
-
objectToCompareTo:
Type: Object
Return Value
Type: Integer
Usage
The implementation of this method returns the following values:
- 0 if this instance and objectToCompareTo are equal
- > 0 if this instance is greater than objectToCompareTo
- < 0 if this instance is less than objectToCompareTo
If this object instance and objectToCompareTo are incompatible, a System.TypeException is thrown.