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;








1















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.










share|improve this question
























  • 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


















1















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.










share|improve this question
























  • 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














1












1








1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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











1 Answer
1






active

oldest

votes


















4














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.






share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    4














    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.






    share|improve this answer



























      4














      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.






      share|improve this answer

























        4












        4








        4







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 8 hours ago









        David ReedDavid Reed

        44.5k82564




        44.5k82564



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

            Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

            199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單