function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
GeetuGeetu 

TestClass for retrieval of custom settings values

Hi, I have a custom setting "XYZ" and Name . I want to write a test class for retriving value of URLLink for custom settin "XYZ" . 
I have written my test class, and have properly inserted values for custom setting and URLLink but still i am getting " 
System.NullPointerException: Attempt to de-reference a null object.
can somebody pls help 


@AuraEnabled
    public static string GetCustomsettingValueName()
    {
        
        Object_Name Obj= Object_Name.getValues('XYZ settin'); 
        return Obj.URLLink;
    }

Testclass : 

 Custom_obj CDH = new Custom_obj();
         Custom_ob.Name = 'Test Custom settinges';
        CDH.URLLink='http://www.Test';
        insert CDH;
kishor chilukurikishor chilukuri
if you mention @isTest(seeAllData = true) then test class can recognize the existing data in the database.
GeetuGeetu
No, i am having @testSetup in my test class, i think i wont be able to use both @testSetup and @isTest(seeAllData = true) together in test class.
Raj VakatiRaj Vakati
You need to try like  below  .. remeber custom settings also custom object so you need to insert the data if you dnt sent the see all data to true 

 
@isTest 
private class Leadzip2Test{
    
    
    static testMethod void testMethodRT(){
	
	 Custom_setting__c cs = new Custom_setting__c() ; 
	 cs.Name='XYZ settin';
	 insert cs ;
	
	 Custom_obj__c CDH = new Custom_obj__c();
         CDH.Name = 'Test Custom settinges';
        CDH.URLLink='http://www.Test';
        insert CDH;
		
    }
    
}

 
GeetuGeetu
hi Raj thanks so mich for the reply, but i am still not able to resolve this issue.Is there any cance you will be available for screen sharing
Raj VakatiRaj Vakati
give me your complete code i will write it for you 
GeetuGeetu
Here is the code :
@AuraEnabled
    public static string GetIsGovernmentYesUrlRedirection()
    {
        
        CDHConfiguration__c cdhConfiguration = CDHConfiguration__c.getValues('CDH Configuration Setting'); 
        return cdhConfiguration.IsGovernmentYesLink__c;
    }