I have 3 lookup relationship with contact and I created a List for each lookup. For every list, I put it on a Set of IDs which is being used in the contact list in order to related the lookup on the contact. I put everything on a wrapper class so that every skill, training or cert will check if the id is matched on the contact Id.
public class pageFilter {
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;}
}
pageFilterList = new List<pageFilter>();
for(Contact cons : contList ){
pgf = new pageFilter();
pgf.employee = cons;
// SKILLS
if(!String.isEmpty(wrapFilter1.skillName1) || !String.isEmpty(wrapFilter2.skillName2) || !String.isEmpty(wrapFilter3.skillName3) || !String.isEmpty(wrapFilter4.skillName4) || !String.isEmpty(wrapFilter5.skillName5) ) {
List<Employee_Skills__c> empSkills = new List<Employee_Skills__c>();
for(Employee_Skills__c empSkill : skillList ){
if(cons.Id == empSkill.Employee_Id__c){
empSkills.add(empSkill);
}
}
pgf.empSkillList = empSkills;
}
pageFilterList.add(pgf);
}
We have 5 filters, each of the filters can search for skill, training or certification.
How to sort the Contact ASC and group the search result by the most number of matched result.