public class PartnerWrapper implements Comparable {
private static final Map<String, Integer> levelsOrder = new Map<String, Integer>{
'Platinum' => 1,
'Gold' => 2,
'Silver' => 3
};
public Account acc {get; set;}
public String level {get; set;}
public Integer compareTo(Object thatObj){
PartnerWrapper that = (PartnerWrapper) thatObj;
Integer thisOrder = defineLevelOrder(this.level);
Integer thatOrder = defineLevelOrder(that.level);
return thisOrder - thatOrder;
}
private Integer defineLevelOrder(String currentlevel){
Integer result = 2147483647;
if(levelsOrder.containsKey(currentlevel)){
result = levelsOrder.get(currentlevel);
}
return result;
}
}
You can control order by additional wrapper static field, that stores level and its order.
private static final Map<String, Integer> levelsOrder = new Map<String, Integer>{
'Platinum' => 1,
'Gold' => 2,
'Silver' => 3
};
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 value 2147483647
. So unknown level
values would be last after sorting