0

I keep getting a null pointer exception but I can't understand why. I do have null checks. I know that the field on the Match__c is null, but I can't understand why that would matter, since it's the field being assigned to.

 if ( taskMap.get(tId).whatId != null && 
    taskMap.get(tId).whatId.getSObjectType() == Match__c.sObjectType) {
    if (taskMap.get(tId).Subject.containsIgnoreCase('Student Started Learning') 
        && taskMap.get(tId).Call_Outcome__c != null) {
            matchesMap.get(taskMap.get(tId).whatId).Call_Outcome_Student_Started_Learning__c 
                = taskMap.get(tId).Call_Outcome__c;
    }

I know matchesMap.get(taskMap.get(tId).whatId).Call_Outcome_Student_Started_Learning__c is null, but it is the variable being assigned to, so why would that be an issue?

  • If the error is thrown from that line it looks like it could be one of two things. That taskMap.get(tId) is null (which we know it isn't based on your null check above), or matchesMap.get(taskMap.get(tId).whatId) is null. Can you confirm neither are null? – Antonio Manente Aug 18 '16 at 3:14
  • 2
    @antonioManente you are a gentleman and a scholar thank you. It was the latter – user3979986 Aug 18 '16 at 3:20
0

It seems like you are missing value in your map. So add containsKey check before getting value out of map.

if (taskMap.containKey(tId) && taskMap.get(tId).whatId != null &&
    taskMap.get(tId).whatId.getSObjectType() == Match__c.sObjectType) {

    if (taskMap.get(tId).Subject.containsIgnoreCase('Student Started Learning') && 
    taskMap.get(tId).Call_Outcome__c != null && 
    matchesMap.containsKey(taskMap.get(tId).whatId)) {

    matchesMap.get(taskMap.get(tId).whatId).Call_Outcome_Student_Started_Learning__c = taskMap.get(tId).Call_Outcome__c;
    }

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.