I have a wrapper class called

public class dashboardLanding{

    @AuraEnabled public String Id{get;set;}
    @AuraEnabled public String patientInitial { get; set; }
    @AuraEnabled public String sex {get;set;}
    @AuraEnabled public Date dob{get;set;}
    @AuraEnabled public String status{get;set;}
    @AuraEnabled public String pathway{get;set;}
    @AuraEnabled public String cycleRecordId{get;set;}
    @AuraEnabled public Date cycleActualDate{get;set;}

    public dashboardLanding() {

    public dashboardLanding(String caseId, String accountInitial, String gender, Date dateOfBirth, String landingStatus, String schemeName, string cycleId, date actualDate) {
        System.debug('Patient Initial -> ' + patientInitial);
         Id = caseId;
         patientInitial = accountInitial;
         sex = gender;
         dob = dateOfBirth;
         status = landingStatus;
         pathway = schemeName;
         cycleRecordId = cycleId;
         cycleActualDate = actualDate;

Now this wrapper class is being called in a

public static List<dashboardLanding> method(){
  //return a list of dashboardLanding

Now my issue is, how can I sort the returned list of record to be sorted by status First: Status (Enrolment Requested, Pending More Info., Ordered, Re-order Available, Ordered, Re-order Not Due, Discontinued)

1 Answer 1


You can do this by implementing Comparable. Your class would need the following changes:

public class dashboardLanding implements Comparable {
  static String[] sortOrder = new String[] { null,'Enrolment Requested','Pending More Info.','Ordered','Re-order Available','Re-order Not Due','Discontinued' };
  public Integer compareTo(Object o) {
    return sortOrder.indexOf(status) - sortOrder.indexOf(((dashboardLanding)o).status);
  // Rest of class is as original code...

From there, you can then sort your items using sort();

dashboardLanding[] dashboards = new dashboardLanding[0];
// Populate list
// ... Then sort

I made some adjustments to the code based on the duplicate status value, so please observe the changes. Also, if this is an inner class, the static variable will need to be stored in another class (only top-level classes can have static variables), but hopefully this will demonstrate how Comparable can be used to sort wrapper objects. You can read more in the documentation at the link in the first paragraph.

  • thanks a lot man!
    – imajmdf
    Commented Apr 30, 2019 at 4:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .