I have recently had help creating a Wrapper class to combine 2 separate objects, Delivery_Note__c and Remittance_Advice__c, into one list, both with their own date fields. The list is then rendered on a Visualforce page, using <apex:repeat>
.
The resulting list needs to be sorted by the date column (calculatedDate). I am trying to use compareTo, but with little success.
I have tried to follow this post which is similar, no luck.
Any thoughts?
UPDATE
As per Adrians suggestion, I have removed the bulk of the class to make the question a little easier to read.
APEX
public class CustomerStatementTableController {
public class Wrapper implements Comparable {
public Delivery_Note__c note {get; private set;}
public Remittance_Advice__c remittance {get; private set;}
public Date calculatedDate {get;private set;}
public Wrapper(Delivery_Note__c n) {
note = n;
dataType = 'note';
calculatedDate = note.Transaction_Date__c;
}
public Wrapper(Remittance_Advice__c r) {
remittance = r;
dataType = 'remittance';
calculatedDate = remittance.Date__c;
}
public Integer compareTo(Object other) {
Wrapper o = (Wrapper)other;
if (note.Transaction_Date__c < remittance.Date__c) return -1;
else if (note.Transaction_Date__c > remittance.Date__c) return 1;
else return 0;
}
}
public List<Wrapper> wrappers { get; private set; }
}
note
andremittance
, and the only method which matters iscompareTo
.