I am trying to implement the comparable interface but I cannot get it to work, nothing seems to make any difference with the ordering of the lists.
public Class MyWrapper implements Comparable {
public ProcessInstanceWorkitem obj1 {get; set;}
public myCustomObject obj2 {get; set;}
public Integer compareTo(Object o)
{
MyWrapper comparemyWrp = (MyWrapper)(o);
if (SORT_BY == ACTOR_SORT) {
return sortByActor(comparemyWrp);
}
return 0;
}
public Integer sortByActor(MyWrapper wrap) {
if (this.obj1.Actor.Name > wrap.obj1.Actor.Name) {
return 1;
}
if (this.obj1.Actor.Name == wrap.obj1.Actor.Name) {
return 0;
}
return -1;
}
}
=== update ===
Here is the code where I am invoking the sort:
I am not sure if I need to call getPendingApprovalList(); in the below code or not but I have tried commenting it out.
public static String ACTOR_SORT = 'obj1.Actor.Name';
public static String SORT_BY = ACTOR_SORT;
And
public PageReference SortbyApprover() {
SORT_BY = ACTOR_SORT;
myWrappers = getPendingApprovalList();
myWrappers.sort();
//system.debug(myWrappers);
return null;
}