Attempt to de-reference a null object when calling class method from Test classDe-Reference a Null ObjectCompilation error with a unit testschema.getglobaldescribe needs test classRegarding Apex classTest Method Null Pointer Exception on Custom Controller TestHow to cover global class and method in test classError on Callout: Attempt to de-reference a null objectBefore Delete Test Class - Getting “De-reference Null Object error on other trigger”Test Class for Trigger Null Pointer ExceptionHello i am not able to get the result from this test class
Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?
Convert GE Load Center to main breaker
C++ logging library
Should I be able to use the Gloom Stalker ranger's Dread Ambusher class feature when attacking before initiative has been rolled to add a d8 damage?
Problem with pronounciation
Recording Spectral Lines at Home
How does AFV select the winning videos?
Is Jesus the last Prophet?
Melave d'Malka on Motze Yom Tov
Why did Robert pick unworthy men for the White Cloaks?
How (un)safe is it to ride barefoot?
How can powerful telekinesis avoid violating Newton's 3rd Law?
How do I avoid typing "git" at the begining of every Git command?
Labels still showing when no Label Features turned on in ArcMap?
That's not my X, its Y is too Z
What does the homotopy coherent nerve do to spaces of enriched functors?
Does a single fopen introduce TOCTOU vulnerability?
Why is it bad to use your whole foot in rock climbing
Placement of positioning lights on A320 winglets
Playing a trill with grace note ending
What is this object?
As easy as Three, Two, One... How fast can you go from Five to Four?
Why do I seem to lose data using this bash pipe construction?
Should I explain the reasons for gaslighting?
Attempt to de-reference a null object when calling class method from Test class
De-Reference a Null ObjectCompilation error with a unit testschema.getglobaldescribe needs test classRegarding Apex classTest Method Null Pointer Exception on Custom Controller TestHow to cover global class and method in test classError on Callout: Attempt to de-reference a null objectBefore Delete Test Class - Getting “De-reference Null Object error on other trigger”Test Class for Trigger Null Pointer ExceptionHello i am not able to get the result from this test class
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to write a test method that calls a method in my class to get some configuration data. The method in my class returns a Map. From my test method, when I call the method in my class, I get an error which happens when I call APIService.getSystemSettings();
System.NullPointerException: Attempt to de-reference a null object
My code is below:
private class APIServiceTest
@isTest static void APITest()
Map<String,String> envSettings = new Map<String,String>();
envSettings = APIService.getSystemSettings();
Here is the class which contains the method I am calling:
public class APIService
static API_Settings__c apiSettings = API_Settings__c.getValues('apisettings')
static Map<String,String> envSettings = new Map<String,String>();
public static Map<String,String> getSystemSettings()
envSettings.put('customerURL', apiSettings.customer_url__c);
Most of my methods in APIService are methods annotateded with @Future(Callout=true) so that is why most of the variables are declared as static methods.
I am trying to determine why I am getting this error and what is needed to fix it.
apex unit-test test-setup
add a comment |
I am trying to write a test method that calls a method in my class to get some configuration data. The method in my class returns a Map. From my test method, when I call the method in my class, I get an error which happens when I call APIService.getSystemSettings();
System.NullPointerException: Attempt to de-reference a null object
My code is below:
private class APIServiceTest
@isTest static void APITest()
Map<String,String> envSettings = new Map<String,String>();
envSettings = APIService.getSystemSettings();
Here is the class which contains the method I am calling:
public class APIService
static API_Settings__c apiSettings = API_Settings__c.getValues('apisettings')
static Map<String,String> envSettings = new Map<String,String>();
public static Map<String,String> getSystemSettings()
envSettings.put('customerURL', apiSettings.customer_url__c);
Most of my methods in APIService are methods annotateded with @Future(Callout=true) so that is why most of the variables are declared as static methods.
I am trying to determine why I am getting this error and what is needed to fix it.
apex unit-test test-setup
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago
add a comment |
I am trying to write a test method that calls a method in my class to get some configuration data. The method in my class returns a Map. From my test method, when I call the method in my class, I get an error which happens when I call APIService.getSystemSettings();
System.NullPointerException: Attempt to de-reference a null object
My code is below:
private class APIServiceTest
@isTest static void APITest()
Map<String,String> envSettings = new Map<String,String>();
envSettings = APIService.getSystemSettings();
Here is the class which contains the method I am calling:
public class APIService
static API_Settings__c apiSettings = API_Settings__c.getValues('apisettings')
static Map<String,String> envSettings = new Map<String,String>();
public static Map<String,String> getSystemSettings()
envSettings.put('customerURL', apiSettings.customer_url__c);
Most of my methods in APIService are methods annotateded with @Future(Callout=true) so that is why most of the variables are declared as static methods.
I am trying to determine why I am getting this error and what is needed to fix it.
apex unit-test test-setup
I am trying to write a test method that calls a method in my class to get some configuration data. The method in my class returns a Map. From my test method, when I call the method in my class, I get an error which happens when I call APIService.getSystemSettings();
System.NullPointerException: Attempt to de-reference a null object
My code is below:
private class APIServiceTest
@isTest static void APITest()
Map<String,String> envSettings = new Map<String,String>();
envSettings = APIService.getSystemSettings();
Here is the class which contains the method I am calling:
public class APIService
static API_Settings__c apiSettings = API_Settings__c.getValues('apisettings')
static Map<String,String> envSettings = new Map<String,String>();
public static Map<String,String> getSystemSettings()
envSettings.put('customerURL', apiSettings.customer_url__c);
Most of my methods in APIService are methods annotateded with @Future(Callout=true) so that is why most of the variables are declared as static methods.
I am trying to determine why I am getting this error and what is needed to fix it.
apex unit-test test-setup
apex unit-test test-setup
edited 8 hours ago
David Reed♦
44.5k82564
44.5k82564
asked 8 hours ago
user1669296user1669296
106110
106110
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago
add a comment |
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago
add a comment |
1 Answer
1
active
oldest
votes
In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation.
Your unit test's setup, whether in your @isTest
or an @testSetup
method, must construct and insert any Custom Settings records you wish to have available to your test code.
You get a NullPointerException
because there is no visible API_Settings__c
instance called apisettings
; it's null
.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f265389%2fattempt-to-de-reference-a-null-object-when-calling-class-method-from-test-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation.
Your unit test's setup, whether in your @isTest
or an @testSetup
method, must construct and insert any Custom Settings records you wish to have available to your test code.
You get a NullPointerException
because there is no visible API_Settings__c
instance called apisettings
; it's null
.
add a comment |
In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation.
Your unit test's setup, whether in your @isTest
or an @testSetup
method, must construct and insert any Custom Settings records you wish to have available to your test code.
You get a NullPointerException
because there is no visible API_Settings__c
instance called apisettings
; it's null
.
add a comment |
In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation.
Your unit test's setup, whether in your @isTest
or an @testSetup
method, must construct and insert any Custom Settings records you wish to have available to your test code.
You get a NullPointerException
because there is no visible API_Settings__c
instance called apisettings
; it's null
.
In unit test context, Custom Settings are treated as data (not metadata), and hence are not visible due to test isolation.
Your unit test's setup, whether in your @isTest
or an @testSetup
method, must construct and insert any Custom Settings records you wish to have available to your test code.
You get a NullPointerException
because there is no visible API_Settings__c
instance called apisettings
; it's null
.
answered 8 hours ago
David Reed♦David Reed
44.5k82564
44.5k82564
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f265389%2fattempt-to-de-reference-a-null-object-when-calling-class-method-from-test-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is it hierarchical custom setting or list custom setting?
– Pranay Jaiswal
8 hours ago
It is list custom setting @PranayJaiswal
– user1669296
8 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
8 hours ago