• Colby Flye
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi Everyone!

I get to write my first apex class! Yay! I am running into a NullPointerException De-Reference A Null Object error. My method is being called in an afterTrigger, please look below...

public static void updatenewCaseRecordTeamFields(List<Case> cases){
    map<Case, Id> CasetoUser = new map<Case,Id>();
    map<Id, User> UserIdtoUser = new map<Id,User>();
    List<Id> OwnerIds = new List<Id>();
        for(Case c:(List<Case>)trigger.new){
            If(c.Owner.Type=='User' && c.OwnerId != null){
               OwnerIds.add(c.OwnerId);
               CasetoUser.put(c,c.OwnerId);
            }
        }
               List<User> userList = [SELECT team__c from User where Id IN: OwnerIds];
            For(User u: userList){
                UserIdtoUser.put(u.Id,u);
            }
                for(Case c:(List<Case>)trigger.new){
                    c.CaseOpenedTeam__c = UserIdtoUser.get(CasetoUser.get(c)).team__c;
                    c.CaseOwnerTeam__c = UserIdtoUser.get(CasetoUser.get(c)).team__c;               
                }
        
    }
The run down is that the code is trying to set fields on case fields based on the Owner of the record, being the user, and update those fields with the users teams. 

Thanks in Advance!