We have a wrapper class which contains different list of custom object. We want to sort it through the field referenced by different custom object. How can we achieve this?
The code below shows a null pointer execution.
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;}
public pageFilterForEmployeeSkills empSkillCompare{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 this.empSkillCompare.compareTo(compareToFilter.empSkillCompare);
}
}
}
global class pageFilterForEmployeeSkills 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;}
public Integer compareTo(Object o) {
pageFilterForEmployeeSkills thatSkill = (pageFilterForEmployeeSkills)o;
if (this.empSkillList[0].Name < thatSkill.empSkillList[0].Name) return -1;
else if (this.empSkillList[0].Name > thatSkill.empSkillList[0].Name) return 1;
else return 0;
}
}
Thanks!
empSkillList[0].Name
, change the data type for empSkillList to List<Wrapper>