1

I have a protected custom setting that I am querying. I have the following statement:

App_name_c key = App_name_c.getValues('secret');

When I run this in the console it works. However, when I run this in the class, it returns this:

System.QueryException: List has no rows for assignment to SObject

Any ideas?

2
  • 2
    Can you post your List code? The problem is there, it's telling you the query is not returning any values and we cannot tell without the code.
    – ddeve
    Commented Jul 13, 2013 at 3:42
  • Did you try defining the class without sharing to see if that gave a different result?
    – Phil B
    Commented Aug 14, 2013 at 14:56

1 Answer 1

5

Are you per any chance getting System.QueryException: List has no rows for assignment to SObject when you run it in test code ?

Custom settings, are data and are just like most sObject data not available by default in test code. For good practise, testing your logic is done data independant and test data is generated in the test itself. You can create and insert custom settings like any sObject with DML.

insert new CustomSetting__c(Name='dummyt', fieldOne__c= 'value1', field2__c='value2');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .