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
jitendra suthar 7jitendra suthar 7 

it is possible to access custom settings in test class without using (SeeAllData=true)

hi ,
i have some trouble during implementation of test method .
Here i am trying to polulate a custom settings in test class but  it is shown that custom settings with that name is already exist .
Here i have a confusion  ,org data are accessible in test class without using (SeeAllData=true)  or not .
 
Pankaj_GanwaniPankaj_Ganwani
Hi,

Yes, it's possible to access custom setting in test classes. All you need to do is to create the custom setting records in test class and then access them.

Thanks,
Pankaj
jitendra suthar 7jitendra suthar 7
i am trying to say that whenever i am trying to insert custom settings with same name which is already exist in org data ,then it shows following error .
caused by: System.DmlException: Insert failed. First exception on row 1; first error: FIELD_INTEGRITY_EXCEPTION, There is already an item in this list with the name Online Specialty Military: [Name]

 
nagalakshminagalakshmi
Hi Jitendra,

Write one apex method in your class or in utiltiy class , insert your custom setting record in that method and return this custom setting through the method.  

Call this method in your test class to get the custom setting value. I am giving sample class below.

public class AccountTest {
     public static account createAccount() {
           // Create your custom setting here
           account a = new account(name ='Test acc');
           insert a;
           return a;
     }
     public static testmethod void runtest() {
        account a = AccountTest.createAccount(); - This will return account values. 
        
     }
​    

}
please let me know if you need any help;

Thanks,
Lakshmi