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
Create a cube from identical 3D objects
As easy as Three, Two, One... How fast can you go from Five to Four?
Suppose leased car is totalled: what are financial implications?
Can I use 220 V outlets on a 15 ampere breaker and wire it up as 110 V?
Melave d'Malka on Motze Yom Tov
What is the proper event in Extended Events to track stored procedure executions?
In American Politics, why is the Justice Department under the President?
Make Gimbap cutter
Why are ambiguous grammars bad?
Why did the World Bank set the global poverty line at $1.90?
What does the homotopy coherent nerve do to spaces of enriched functors?
Should I list a completely different profession in my technical resume?
Is Lambda Calculus purely syntactic?
Why do the TIE Fighter pilot helmets have similar ridges as the rebels?
Am I allowed to determine tenets of my contract as a warlock?
Prove that the infinite series equals 1
Linked novellas where humans are engineered to adapt to a variety of environments
When to use и or а as “and”?
Dedicated bike GPS computer over smartphone
Entered UK using my now-lost UK passport; can I go to Spain using my US passport?
Mathematica 12 has gotten worse at solving simple equations?
In Pandemic, why take the extra step of eradicating a disease after you've cured it?
What does "lit." mean in boiling point or melting point specification?
How many sets of dice do I need for D&D?
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
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 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
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 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
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 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
7 hours ago
It is list custom setting @PranayJaiswal
– user1669296
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 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
7 hours ago
You have to insert the custom settings in testContext in testSetup. See David's answer.
– Pranay Jaiswal
7 hours ago