Skip to main content
edited tags
Link
sfdcfox
  • 501.7k
  • 21
  • 473
  • 828
added 889 characters in body
Source Link
Jayee
  • 45
  • 1
  • 2
  • 9
    public Map<Id, AggregateResult> mapSummary {
        get {
            AggregateResult[] arResult = [select    Employee_Name__c, min(CareerJoinDate__c) enterdate, max(CareerExitDate__c) exitdate 
                                      from      Career__c 
                                      where     Employee_Name__c =: listIdEmployee
                                      Group by  Employee_Name__c];
            if(!arResult.isEmpty()){                                          
                for(AggregateResult ar : arResult) {
                mapSummary.put((Id)ar.get('Employee_Name__c'), ar);
                }
            }        
            return mapSummary;
        }
        set;
}

    public List<String> listIdEmployee {
    get {
        if(listIdEmployee == null) {
            System.debug('JSON String : ' + ApexPages.currentPage().getParameters().get('ids'));

            listIdEmployee = new List<String>();
            listIdEmployee = (List<String>) JSON.deserialize(ApexPages.currentPage().getParameters().get('ids'), List<String>.class);
            System.debug('listIdEmployee : ' + listIdEmployee);
        }
        
        return listIdEmployee;
    }
    set;
}
    public class WrapperEmployee {
    public Employee__c objEmployee {get;set;}
    public String totalCareer {get;set;}


    public WrapperEmployee(Employee__c objEmployee, String totalCareer){
        this.objEmployee = objEmployee;
        this.totalCareer = totalCareer;
        System.debug('objEmployee [WrapperEmployee]'+objEmployee);
        System.debug('totalCareer [WrapperEmployee]'+totalCareer);
    }
}
    public List<Employee__c> listEmployee {
    get {
        if(listEmployee == null) {
            listEmployee = new List<Employee__c>();

            listEmployee = Database.query(getListEmployeeQuery());
            System.debug('listEmployee : ' + listEmployee);
            }          
        return listEmployee; 
    }
    set;
}


    public List<WrapperEmployee> listWrapperEmployee {
    get {
        System.debug('listEmployee [WrapperEmployee]'+listEmployee);
        System.debug('mapSummary [WrapperEmployee]'+mapSummary);
        //WrapperEmployee objEmpWrap = new WrapperEmployee();
        String totalCar;
            for(Employee__c obj : listEmployee){
                if(!mapSummary.isEmpty() || mapSummary.get('enterdate')!=null && mapSummary.get('exitdate')!=null) {
                    Date entDate = Date.valueOf(mapSummary.get(obj.Id).get('exitdate'));
                    Date extDate = Date.valueOf(mapSummary.get(obj.Id).get('enterdate'));
                    totalCar = String.valueOf(extDate.year() - entDate.year());
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);


                }else{                        
                    totalCar = obj.WorkPeriode__c;                                                
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);

                }

            }

            return listWrapperEmployee;
        
    }
    set;
}
    public List<String> listIdEmployee {
    get {
        if(listIdEmployee == null) {
            System.debug('JSON String : ' + ApexPages.currentPage().getParameters().get('ids'));

            listIdEmployee = new List<String>();
            listIdEmployee = (List<String>) JSON.deserialize(ApexPages.currentPage().getParameters().get('ids'), List<String>.class);
            System.debug('listIdEmployee : ' + listIdEmployee);
        }
        
        return listIdEmployee;
    }
    set;
}
    public class WrapperEmployee {
    public Employee__c objEmployee {get;set;}
    public String totalCareer {get;set;}


    public WrapperEmployee(Employee__c objEmployee, String totalCareer){
        this.objEmployee = objEmployee;
        this.totalCareer = totalCareer;
        System.debug('objEmployee [WrapperEmployee]'+objEmployee);
        System.debug('totalCareer [WrapperEmployee]'+totalCareer);
    }
}
    public List<Employee__c> listEmployee {
    get {
        if(listEmployee == null) {
            listEmployee = new List<Employee__c>();

            listEmployee = Database.query(getListEmployeeQuery());
            System.debug('listEmployee : ' + listEmployee);
            }          
        return listEmployee; 
    }
    set;
}


    public List<WrapperEmployee> listWrapperEmployee {
    get {
        System.debug('listEmployee [WrapperEmployee]'+listEmployee);
        System.debug('mapSummary [WrapperEmployee]'+mapSummary);
        //WrapperEmployee objEmpWrap = new WrapperEmployee();
        String totalCar;
            for(Employee__c obj : listEmployee){
                if(!mapSummary.isEmpty() || mapSummary.get('enterdate')!=null && mapSummary.get('exitdate')!=null) {
                    Date entDate = Date.valueOf(mapSummary.get(obj.Id).get('exitdate'));
                    Date extDate = Date.valueOf(mapSummary.get(obj.Id).get('enterdate'));
                    totalCar = String.valueOf(extDate.year() - entDate.year());
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);


                }else{                        
                    totalCar = obj.WorkPeriode__c;                                                
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);

                }

            }

            return listWrapperEmployee;
        
    }
    set;
}
    public Map<Id, AggregateResult> mapSummary {
        get {
            AggregateResult[] arResult = [select    Employee_Name__c, min(CareerJoinDate__c) enterdate, max(CareerExitDate__c) exitdate 
                                      from      Career__c 
                                      where     Employee_Name__c =: listIdEmployee
                                      Group by  Employee_Name__c];
            if(!arResult.isEmpty()){                                          
                for(AggregateResult ar : arResult) {
                mapSummary.put((Id)ar.get('Employee_Name__c'), ar);
                }
            }        
            return mapSummary;
        }
        set;
}

    public List<String> listIdEmployee {
    get {
        if(listIdEmployee == null) {
            System.debug('JSON String : ' + ApexPages.currentPage().getParameters().get('ids'));

            listIdEmployee = new List<String>();
            listIdEmployee = (List<String>) JSON.deserialize(ApexPages.currentPage().getParameters().get('ids'), List<String>.class);
            System.debug('listIdEmployee : ' + listIdEmployee);
        }
        
        return listIdEmployee;
    }
    set;
}
    public class WrapperEmployee {
    public Employee__c objEmployee {get;set;}
    public String totalCareer {get;set;}


    public WrapperEmployee(Employee__c objEmployee, String totalCareer){
        this.objEmployee = objEmployee;
        this.totalCareer = totalCareer;
        System.debug('objEmployee [WrapperEmployee]'+objEmployee);
        System.debug('totalCareer [WrapperEmployee]'+totalCareer);
    }
}
    public List<Employee__c> listEmployee {
    get {
        if(listEmployee == null) {
            listEmployee = new List<Employee__c>();

            listEmployee = Database.query(getListEmployeeQuery());
            System.debug('listEmployee : ' + listEmployee);
            }          
        return listEmployee; 
    }
    set;
}


    public List<WrapperEmployee> listWrapperEmployee {
    get {
        System.debug('listEmployee [WrapperEmployee]'+listEmployee);
        System.debug('mapSummary [WrapperEmployee]'+mapSummary);
        //WrapperEmployee objEmpWrap = new WrapperEmployee();
        String totalCar;
            for(Employee__c obj : listEmployee){
                if(!mapSummary.isEmpty() || mapSummary.get('enterdate')!=null && mapSummary.get('exitdate')!=null) {
                    Date entDate = Date.valueOf(mapSummary.get(obj.Id).get('exitdate'));
                    Date extDate = Date.valueOf(mapSummary.get(obj.Id).get('enterdate'));
                    totalCar = String.valueOf(extDate.year() - entDate.year());
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);


                }else{                        
                    totalCar = obj.WorkPeriode__c;                                                
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);

                }

            }

            return listWrapperEmployee;
        
    }
    set;
}
Source Link
Jayee
  • 45
  • 1
  • 2
  • 9

Error : Attempt to de-reference a null object ; on map variable

Class.ResourceProfileController.__sfdc_mapSummary: line 137, column 1 Class.ResourceProfileController.__sfdc_listWrapperEmployee: line 162, column 1

--> Error on the Variable mapSummary

Hello

I'm trying to put Map<Id, AggregateResult> id : Employee ID, AggregateResult (Join(min),Resign(max) Date)

To export Personnel profile for a DOC in the VF Page for calculating working years but it keeps display an above errors. when i tried to reference in the VF page

  <apex:repeat value="{!listWrapperEmployee}" var="wrap">
{!wrap.objEmployee.MainRole__c}

but i still checked the isEmpty() on AggregateResult .. how should i figure this out?

    public List<String> listIdEmployee {
    get {
        if(listIdEmployee == null) {
            System.debug('JSON String : ' + ApexPages.currentPage().getParameters().get('ids'));

            listIdEmployee = new List<String>();
            listIdEmployee = (List<String>) JSON.deserialize(ApexPages.currentPage().getParameters().get('ids'), List<String>.class);
            System.debug('listIdEmployee : ' + listIdEmployee);
        }
        
        return listIdEmployee;
    }
    set;
}
    public class WrapperEmployee {
    public Employee__c objEmployee {get;set;}
    public String totalCareer {get;set;}


    public WrapperEmployee(Employee__c objEmployee, String totalCareer){
        this.objEmployee = objEmployee;
        this.totalCareer = totalCareer;
        System.debug('objEmployee [WrapperEmployee]'+objEmployee);
        System.debug('totalCareer [WrapperEmployee]'+totalCareer);
    }
}
    public List<Employee__c> listEmployee {
    get {
        if(listEmployee == null) {
            listEmployee = new List<Employee__c>();

            listEmployee = Database.query(getListEmployeeQuery());
            System.debug('listEmployee : ' + listEmployee);
            }          
        return listEmployee; 
    }
    set;
}


    public List<WrapperEmployee> listWrapperEmployee {
    get {
        System.debug('listEmployee [WrapperEmployee]'+listEmployee);
        System.debug('mapSummary [WrapperEmployee]'+mapSummary);
        //WrapperEmployee objEmpWrap = new WrapperEmployee();
        String totalCar;
            for(Employee__c obj : listEmployee){
                if(!mapSummary.isEmpty() || mapSummary.get('enterdate')!=null && mapSummary.get('exitdate')!=null) {
                    Date entDate = Date.valueOf(mapSummary.get(obj.Id).get('exitdate'));
                    Date extDate = Date.valueOf(mapSummary.get(obj.Id).get('enterdate'));
                    totalCar = String.valueOf(extDate.year() - entDate.year());
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);


                }else{                        
                    totalCar = obj.WorkPeriode__c;                                                
                    //objEmpWrap.objEmployee = obj;
                    //objEmpWrap.totalCareer = totalCar;
                    WrapperEmployee objEmpWrap = new WrapperEmployee(obj,totalCar);
                    listWrapperEmployee.add(objEmpWrap);

                }

            }

            return listWrapperEmployee;
        
    }
    set;
}