2
votes

The test class is as follows: I am trying to set the RecordType.Name in the test class but it gives me the message "System.NullPointerException: Attempt to de-reference a null object class.TestAcctHierWarnDisplay.tstWarningDisplay1: line 45, column 3 External entry point". The record types exist. I am not sure what I am missing. Gets the exception at myacct.RecordType.Name = 'Master Account';

1
Welcome to Stack Overflow. Please provide the necessary details to diagnose the problem. Seeing the code is necessary for that. - Daniel Fischer
It seems light but there is actually enough information here if you're familiar with the platform. - Matt Lacey

1 Answers

5
votes

You should set the record type by ID, not by name:

id idRT = [select Id from RecordType where SobjectType = 'Account' and DeveloperName = 'RTDevName].Id; 

Account sAcct = new Account();
sAcct.RecordTypeId = idRT;

Also, note that I'm using developer name, this is the equivalent of the API name on object fields, the idea being that the actual name is a label and could be changed for frontend purposes.

FYI: The reason you're getting an exception is because the account is not assigned a record type at this stage, so myacct.RecordType is null, which you're trying to dereference when accessing the Name field on it.