0

Can someone help us with regards to sort based on the number of matched filtered. We need to prioritized the number of matched filtered on SKILLS rather than (skills + training / skills + certification)

In the table below, it shows that after we sort based on the PRIMARY SKILL TYPE, the system get the combination of Skill + Training. How to resolve this? enter image description here

    // wrapper for results
    global class pageFilter implements comparable {

    public Contact employee{get;set;}
    public pageFilter other {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 String nameOfSkill;
    public String profOfSkill;
    public String yoeOfSkill;
    public String typeofSkill;   
    public String nameOfTraining;   
    public String nameOfCertification;
    public String nameOfEmployee;

    public void transferName (){
        if (empSkillList != null) { 
            for(Employee_Skills__c eSkill : empSkillList){
                this.nameOfSkill = eSkill.Skill_ID__r.Name;
                this.profOfSkill = eSkill.Proficiency__c;
                this.yoeOfSkill = eSkill.Year_of_Experience__c;
                this.typeOfSkill = eSkill.Skill_Type__c;
            }

        }

        if (empCertificationList != null) {           
            for(Employee_Certification__c eCertification : empCertificationList){
                 this.nameOfCertification = eCertification.Certification_ID__r.Name;   
            }               
        }

        if (empTrainingList != null) {           
            for(Employee_Training__c eTraining : empTrainingList){
                 this.nameOfTraining = eTraining.Training_ID__r.Name;   
            }               
        }


        if (employee != null) {
            this.nameOfEmployee = employee.Name;
        }


    } 

     // Grouped based on the number of matched filter 
    public integer totalCount { 
       get {                     
            transferName();                         
            Integer skillCount = (empSkillList == null) ? 0 : empSkillList.size();
            Integer certificationCount = (empCertificationList == null) ? 0 : empCertificationList.size();
            Integer trainingCount = (empTrainingList == null) ? 0 : empTrainingList.size();

            return skillCount + certificationCount + trainingCount;                                       
        }                      
    } 

    public Integer compareTo(Object compareTo) {
    pageFilter compareToFilter = (pageFilter)compareTo;
    pageFilter other = (pageFilter)compareTo;
        if(this.totalCount < compareToFilter.totalCount) {
            return 1;
        } else if(this.totalCount > compareToFilter.totalCount) {
            return -1;
        } else {
            return compareToFields(other);
        }                       

    }

   // sort the 3 custom field based on the requirements        
   Integer compareToFields(pageFilter other) {
       String skName = other != null ? ((pageFilter)other).nameOfSkill : ''; 
       String skProf = other != null ? ((pageFilter)other).profOfSkill : '';
       String skYoe = other != null ? ((pageFilter)other).yoeOfSkill : '';   
       String skType = other != null ? ((pageFilter)other).typeOfSkill : '';   
       String trName = other != null ? ((pageFilter)other).nameOfTraining : '';
       String certName = other != null ? ((pageFilter)other).nameOfCertification : '';
       String empName = other != null ? ((pageFilter)other).nameOfEmployee : '';

        if(this.typeOfSkill <> skType) {
            return this.typeOfSkill.compareTo(skType);
        } else{
            if (this.nameOfSkill <> skName){                   
                return this.nameOfSkill.compareTo(skName);                   
            } else {
                if(this.profOfSkill <> skProf){        
                    return skProf.compareTo(this.profOfSkill);
                } else {
                    if (this.yoeOfSkill <> skYoe) {
                        return skYoe.compareTo(this.yoeOfSkill); 
                    } else {
                        if (this.nameOfCertification <> certName) {
                            return this.nameOfCertification.compareto(certName);         
                        } else {
                            if (this.nameOfTraining <> trName) {
                                return this.nameOfTraining.compareTo(trName);
                            } else {
                                if (this.nameOfEmployee <> empName) {
                                    return this.nameOfEmployee.compareto(empName);
                                }
                            }
                        }
                    }
                } 
            }            
        }

   return 0;          
   }


} // end of pageFilter comparable
2
  • Can you provide a simpler example of the sort order you are wanting? Generally speaking you can just adjust the compareTo method as required. Apr 11 '17 at 8:19
  • Hi @DanielBallinger we're trying to search for 2 skills and 1 training from the table result above. The contact/employee record that has 2 skills should appear first before the the contact/employee record that has 1 skill and 1 training regardless of its skill type.
    – lone
    Apr 11 '17 at 9:00
1

we're trying to search for 2 skills and 1 training from the table result above. The contact/employee record that has 2 skills should appear first before the the contact/employee record that has 1 skill and 1 training regardless of its skill type.

You need to compare first by the skill type and then by the sum of the remaining factors.

E.g.

public Integer skillCount {
    get { return (empSkillList == null) ? 0 : empSkillList.size(); }
}

public Integer compareTo(Object compareTo) {
    pageFilter compareToFilter = (pageFilter)compareTo;

    // Compare based on skills alone initially.
    if(this.skillCount  < compareToFilter.skillCount ) {
        return 1;
    } else if(this.skillCount > compareToFilter.skillCount ) {
        return -1;
    }

    // Perhaps only compare the combined certificationCount and trainingCount
    if(this.totalCount < compareToFilter.totalCount) {
        return 1;
    } else if(this.totalCount > compareToFilter.totalCount) {
        return -1;
    } else {
        return compareToFields(compareToFilter);
    }                       

}
2
  • Hi @Daniel Ballinger, what if we searched for 2 Training, 1 certification and 1 skill. We need to prioritized also matched result with 2-training over 1-training/1-certification and 1 training/1skill.
    – lone
    Apr 17 '17 at 0:50
  • same with certification. If we searched for 2 Certification, 1 Training and 1 skill. we need to prioritized 2-Certification over 1-training/1-certification and 1 certification/1skill.
    – lone
    Apr 17 '17 at 1:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.