1

I have got some problem, can anyone help me solve this one?

here my problem

Here is my controller

public LIST<SelectOption> getallEmployee(){      
        LIST<HREMPINFO__c> empMember = [SELECT Id, Name, Full_Name__r.Name FROM HREMPINFO__c WHERE Id IN 
                                        (SELECT Employee_No__c FROM PYEMPPAYPERIOD__c WHERE Period__r.Period__r.Id =: selectedPeriod)
                                        ORDER BY Name];

        LIST<HREMPASSIGNMENT__c> empAssignment = [SELECT Position_Name__c, Position_Name__r.Name, Employee_No__c  FROM HREMPASSIGNMENT__c];

        LIST<SelectOption> empList = new LIST<SelectOption>();

        for(HREMPINFO__c eM : empMember){
            for(HREMPASSIGNMENT__c eA : empAssignment){
                if(eA.Employee_No__c == eM.Id){
                    picklistVal = eM.Full_Name__r.Name + ' - ' + eM.Name + ' - ' +eA.Position_Name__r.Name;
                    empList.add(new SelectOption(eM.Id, picklistVal));}
                }
            }
            return empList;
        }
  • You can Convert 'empAssignment' List as Set. – SFDC Mafia - VIC Sep 20 '16 at 10:18
  • how the body of SET, can gv me the code how i convert it? @SFDCMafia – Vikolai Sep 20 '16 at 10:28
  • Better to create MAP of Employee_No__c and Position_Name__r.Name MAP<String, String> empAssignment, Since you need name value in your picklist. – SFDC Mafia - VIC Sep 20 '16 at 10:37
  • i dont understand, can u modify my code and post it here? i want to see it through the difference of my code , so i can understand it, hehe @SFDCMafia – Vikolai Sep 20 '16 at 10:45
2
public LIST<SelectOption> getallEmployee(){      
    LIST<HREMPINFO__c> empMember = [SELECT Id, Name, Full_Name__r.Name FROM HREMPINFO__c WHERE Id IN 
                                    (SELECT Employee_No__c FROM PYEMPPAYPERIOD__c WHERE Period__r.Period__r.Id =: selectedPeriod)
                                    ORDER BY Name];

    LIST<HREMPASSIGNMENT__c> empAssignment = [SELECT Position_Name__c, Position_Name__r.Name, Employee_No__c  FROM HREMPASSIGNMENT__c];

    LIST<SelectOption> empList = new LIST<SelectOption>();

    MAP<String, String> picklistVal  = new MAP<String, String>();

    for(HREMPINFO__c eM : empMember){
    for(HREMPASSIGNMENT__c eA : empAssignment){
        if(eA.Employee_No__c == eM.Id){
            if(!picklistVal.containskey(eA.Employee_No__c)){
                picklistVal.put(eA.Employee_No__c, eM.Full_Name__r.Name + ' - ' + eM.Name + ' - ' +eA.Position_Name__r.Name);
                empList.add(new SelectOption(eM.Id, picklistVal.get(eA.Employee_No__c)));}
            }
        }
    }


        return empList;
    }
  • Changed your variable 'picklistVal' from list to MAP. comment your previous defined 'picklistVal' variable. Hope this will help you. – SFDC Mafia - VIC Sep 20 '16 at 11:34
  • thanks for feedback , but now i got new error, the error message : Illegal assignment from String to Map<String,String> @SFDC Mafia – Vikolai Sep 21 '16 at 7:24
  • f(!picklistVal.containskey(eA.Employee_No__c)){ picklistVal.put(eA.Employee_No__c, eM.Full_Name__r.Name + ' - ' + eM.Name + ' - ' +eA.Position_Name__r.Name); empList.add(new SelectOption(eM.Id, picklistVal.get(eA.Employee_No__c)));} } – SFDC Mafia - VIC Sep 21 '16 at 8:10
  • thanks alot sir! it work! @SFDC Mafia btw can u explain to me how map works sir? – Vikolai Sep 21 '16 at 9:02
  • Go through blog.jeffdouglas.com/2011/01/06/fun-with-salesforce-collections . This might help you to understand – SFDC Mafia - VIC Sep 21 '16 at 9:59

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.