• Brodie Lawton
  • NEWBIE
  • 10 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 4
    Replies
Hi, Hope someone can help!

When I am calling a method from an instance of a class, I am getting the attempt to dereference a null object when calling a class error. I have tried building in validation to stop null values from being allowed to pass through but to no avail.

My code is below:
// department_Field_Population - Written by Brodie Lawton 10/01/2019
    // Class takes the current Case(s) and iterates through them. If the Department__c field is a triage department
    // and the owner is not a triage queue, then set Department__c to the appropriate department for the running user
    // 
    public Case[] department_Field_Population(List<Case> caseRecords){ 
        List<Case> toUpdate = new List<Case>();
        for (Case c : caseRecords){
            if (!(string.valueOf(c.Owner.Name).Contains('Triage')) && (c.Department__c.Contains('Triage'))){ //If the owner name contains triage, and the department does not
                if (UserInfo.getUserRoleId() == '00E0Y000000XzuUUAS'){ //If the user belongs to 2nd line support, change department__c to 2nd line
                    Case toAdd = new Case(Id = c.Id, Department__c = '2nd Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E0Y000000x6oPUAQ'){ //If the user belongs to 1nd line support, change department__c to 1nd line
                    Case toAdd= new Case(Id = c.Id, Department__c = '1st Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaMEAW' || UserInfo.getUserRoleId() == '00E1v000001ZGaHEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Development Team');
                    toUpdate.add(toAdd);
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaCEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Informatics Team');
                    toUpdate.add(toAdd);
                }
            }
        }
        return toUpdate;
    }
It's quite simple code (explanation included in comments), and I have always been able to get past this error before.

Hope someone can help me out!

Thanks.
 
Hi, Hope someone can help!

When I am calling a method from an instance of a class, I am getting the attempt to dereference a null object when calling a class error. I have tried building in validation to stop null values from being allowed to pass through but to no avail.

My code is below:
// department_Field_Population - Written by Brodie Lawton 10/01/2019
    // Class takes the current Case(s) and iterates through them. If the Department__c field is a triage department
    // and the owner is not a triage queue, then set Department__c to the appropriate department for the running user
    // 
    public Case[] department_Field_Population(List<Case> caseRecords){ 
        List<Case> toUpdate = new List<Case>();
        for (Case c : caseRecords){
            if (!(string.valueOf(c.Owner.Name).Contains('Triage')) && (c.Department__c.Contains('Triage'))){ //If the owner name contains triage, and the department does not
                if (UserInfo.getUserRoleId() == '00E0Y000000XzuUUAS'){ //If the user belongs to 2nd line support, change department__c to 2nd line
                    Case toAdd = new Case(Id = c.Id, Department__c = '2nd Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E0Y000000x6oPUAQ'){ //If the user belongs to 1nd line support, change department__c to 1nd line
                    Case toAdd= new Case(Id = c.Id, Department__c = '1st Line Support'); //Creates temp case to put into toUpdate list
                    toUpdate.add(toAdd);// Adds temp case to the toUpdate list
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaMEAW' || UserInfo.getUserRoleId() == '00E1v000001ZGaHEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Development Team');
                    toUpdate.add(toAdd);
                }
                if (UserInfo.getUserRoleId() == '00E1v000001ZGaCEAW'){ //If the user is a Salesforce user, change department to Dev team
                    Case toAdd = new Case(Id = c.Id, Department__c = 'Informatics Team');
                    toUpdate.add(toAdd);
                }
            }
        }
        return toUpdate;
    }
It's quite simple code (explanation included in comments), and I have always been able to get past this error before.

Hope someone can help me out!

Thanks.