I have a wrapper class which is sorted by the totalCount of the size of the three list (empSkillList, empTrainingList, and empCertificationList). Can I sort it also by the fields inside the list of the custom object? If yes, how to do so? Or will I convert it first to a list of string so I can compare it?
global class pageFilter implements comparable {
public Contact employee{get;set;}
public List<Employee_Skills__c> empSkillList{get;set;}
public List<Employee_Training__c> empTrainingList{get;set;}
public List<Employee_Certification__c> empCertificationList{get;set;}
//related list of skill, training and Cert
public List<Employee_Skills__c> relatedSkillList{get;set;}
public List<Employee_Training__c> relatedTrainingList{get;set;}
public List<Employee_Certification__c> relatedCertificationList{get;set;}
public integer totalCount {
get {
// Grouped based on the number of matched filter
if (empSkillList != null && empTrainingList == null && empCertificationList == null) {
return empSkillList.size();
}
if (empTrainingList != null && empSkillList == null && empCertificationList == null) {
return empTrainingList.size();
}
if (empCertificationList != null && empSkillList == null && empTrainingList == null) {
return empCertificationList.size();
}
if (empSkillList != null && empTrainingList != null && empCertificationList == null ) {
return empSkillList.size() + empTrainingList.size();
}
if (empSkillList != null && empTrainingList == null && empCertificationList != null ) {
return empSkillList.size() + empCertificationList.size();
}
if (empSkillList == null && empTrainingList != null && empCertificationList != null) {
return empTrainingList.size() + empCertificationList.size();
}
if (empSkillList != null && empTrainingList != null && empCertificationList != null ) {
return empSkillList.size() + empTrainingList.size() + empCertificationList.size();
}
return 0;
}
}
public Integer compareTo(Object compareTo) {
pageFilter compareToFilter = (pageFilter)compareTo;
if(this.totalCount < compareToFilter.totalCount) {
return 1;
} else if(this.totalCount > compareToFilter.totalCount) {
return -1;
} else {
// You could check further criteria when counts are the same.
return 0;
}
}
}
Thanks!