0

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 : 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 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;
}

1 Answer 1

1

The map doesn't appear to be initialized, so you need to do that first:

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];
        // initialize this first
        mapSummary = new map<Id, AggregateResult>();
        for(AggregateResult ar : arResult) {
            mapSummary.put((Id)ar.get('Employee_Name__c'), ar);
        }
        return mapSummary;
    }
    set;
}

In this special case, you can also just add an alias to avoid needing to allocate memory:

public Map<Id, AggregateResult> mapSummary {
    get {
        return new Map<Id, AggregateResult>([select    Employee_Name__c Id, min(CareerJoinDate__c) enterdate, max(CareerExitDate__c) exitdate 
                                  from      Career__c 
                                  where     Employee_Name__c =: listIdEmployee
                                  Group by  Employee_Name__c]);
    }
    set;
}

Note the special alias of Id (case sensitive) to create the map automatically.

3
  • AggregateResult error has fixed Thanks for comment fox! but it still returns error on Class.ResourceProfileController.__sfdc_listWrapperEmployee: line 162, column 1 after listWrapperEmployee = new List<WrapperEmployee>(); initialization
    – Jayee
    Commented Feb 13, 2019 at 6:21
  • @Jayee I don't see that in your code. You seem to have a problem initializing variables. You'll need to initialze variables before you use them. Null Pointer Exceptions are almost always because you did not initialize a variable.
    – sfdcfox
    Commented Feb 13, 2019 at 6:40
  • Thanks bunch! it has solved~ it was an logic error which Id key value has not founded in mapSummary! Have a great day
    – Jayee
    Commented Feb 13, 2019 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .