I have created a wrapper which contains an account record and a string describing the level of account Platinum, Gold, Silver
.
public class PartnerWrapper implements Comparable {
public Account acc;
public String level;
}
So how can I sort this wrapper list (using compareTo
method as I have implemented my class with Comparable
interface) first displaying results for Platinum
, then Gold
and then Silver
?
If this cannot be achieved using Comparable
interface, then please provide sample code snippet.
Best Answer
You can control order by additional wrapper static field, that stores level and its order.
Do not give field
public
access modifiers without properties, so I added properties as well.If level is not in order defining field, than order of it is a max
Integer
apex value2147483647
. So unknownlevel
values would be last after sorting