You need to sign in to do that
Don't have an account?

Custom Setting reference creates: System.NullPointerException in Test Method
I have a page that iFrames another site and uses a simple class to get the URL and userid. I changed the class to use the Custom Settings for the URL instead of hardcoding it into the code. It works; but I get the following error when running the test: Message: System.NullPointerException: Attempt to de-reference a null object. Stack Trace: Class.clsPMNotes.<init>: line 14, column 1 Class.clsPMNotes.testPMNotes: line 20, column 1
It looks like this "PmNotesSite__c.getInstance('DefaultSiteName').Site__c" is the culprit.
Here's the class
public class clsPMNotes
{
public string prpIFrameSourceURL {get;set;}
public clsPMNotes()
{
prpIFrameSourceURL = PmNotesSite__c.getInstance('DefaultSiteName').Site__c + Userinfo.getUserId();
}
public static testMethod void testPMNotes()
{
Test.StartTest();
clsPMNotes obCLS = new clsPMNotes();
Test.StopTest();
}
}
Thanks much in advance.
Data in Custom Settings are treated like normal objects during tests - so if you are using api v24 or above, the data is not visible to the test script
You either need to set your test to have access to all data, or create new values in the custom setting at the start of the test...
All Answers
Data in Custom Settings are treated like normal objects during tests - so if you are using api v24 or above, the data is not visible to the test script
You either need to set your test to have access to all data, or create new values in the custom setting at the start of the test...
Thanks much; I created the data and test passed with flying colors.