I'm not sure how to write this, but I know what the issue is. The following can be triggered by Insert or Update. Below, mapOfEnroll is Trigger.oldMap. I know the mapOfEnroll value is null on Insert and throwing the NullPointerException, I'm just not sure the right if statement to route it one way or another:
FOR(Enrollment__c e :newEnroll){
IF(mapOfEnroll.get(e.Id)!=null){
IF(enrlCode.containsKey(e.Lead__r.Enrollment_Code__c) && !enrlCode.containsKey(mapOfEnroll.get(e.Id).Lead__r.Enrollment_Code__c)){ //If Old Enrl Code wasn't PT but now is
enrlListPT.add(e);
}
IF(!enrlCode.containsKey(e.Lead__r.Enrollment_Code__c) && enrlCode.containsKey(mapOfEnroll.get(e.Id).Lead__r.Enrollment_Code__c)){ //If Old Enrl Code was PT but now isn't
enrlListFT.add(e);
}
} ELSE {
IF(enrlCode.containsKey(e.Lead__r.Enrollment_Code__c)){ //If Enrl Code is PT
enrlListPT.add(e);
}
IF(!enrlCode.containsKey(e.Lead__r.Enrollment_Code__c)){ //If Enrl Code Isn't PT
enrlListFT.add(e);
}
}
}
IF(mapOfEnroll.get(e.Id)!=null){
Throws a nullPointerException as well. I've tried removing it, but the next line references mapOfEnroll as well and throws nullPointerException on insert as well. I've also tried:
IF(Trigger.isUpdate){
but I found none of the code is triggered - not even the else statement. Any help on this? If update I want to see if the Enrollment_Code__c is changed from an value in the map to a value not in the map (and vise versa), and if insert I want to see if the value is in the map or not.