I've been using Custom Settings for a while, and now I'm running into situations where I don't see the results coming back - this setting is one of the first I created, to turn code on & off, although this particular value/reference is new:

The API Name is NxCode_Switch__c, and it has values for Active(Active__c) and Debug(Debug__c), among others. I reference it the way I've been doing (although I typically use .getValues()):

        NxCode_Switch__c callRefAssociation = NxCode_Switch__c.getInstance('Call Reference processing');
        Boolean isActive = (callRefAssociation == null || callRefAssociation.isActive__c == false) ? false : true;
        Boolean bDebug = (callRefAssociation == null || (isActive == false || callRefAssociation.Debug__c == false)) ? false : true;

Pretty straightforward. Both the code & this particular value of custom setting are in the same Sandbox, but now both getInstance() and getValues() are returning null.

I'm using eclipse, API version 31.0, for what that's worth.

  • How do you know it is returning null, it should be returning false and have the same result as null in the code you posted. Also is this in a test context? – Eric Jan 11 '16 at 17:13
  • If I insert a debug statement after that code and evaluate callRefAssociation it returns null, though there is an NxCode_Switch__c record with that name. This is whether it's in a test scenario or not. – Duncan Stewart Jan 12 '16 at 19:06
  • 2
    If a test context you have to insert the values during the test first. I also believe the name of the instance record is case sensitive. Can you post the debug from Map<String,NxCode_Switch__c> callRefAssociation = NxCode_Switch__c.getAll(); both from your class and the execution in the dev console – Eric Jan 12 '16 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.