One of the most basic and versatile sObject methods is get. For example:

My_Object__c record = [SELECT Name FROM My_Object__c LIMIT 1];
system.assertNotEquals(null, record.get('Name'));

However, this function no longer seems to work on Custom Settings unless I query for them explicitly. At least there is one checkbox field (among many) on my Custom Setting that is returning null.

final String EXISTING_NAME = 'Some Name that exists';
My_Custom_Setting__c recordByQuery = [
    SELECT SomeBoolean__c
    FROM My_Custom_Setting__c
My_Custom_Setting__c recordByGetAll = My_Custom_Setting__c.getAll().get(EXISTING_NAME);
My_Custom_Setting__c recordByGetInstance = My_Custom_Setting__c.getInstance(EXISTING_NAME);

system.assertEquals(true, recordByQuery.SomeBoolean__c); // succeeds
system.assertEquals(true, recordByGetAll.SomeBoolean__c); // succeeds
system.assertEquals(true, recordByGetInstance.SomeBoolean__c); // succeeds

system.assertEquals(true, recordByQuery.get('SomeBoolean__c')); // succeeds
system.assertEquals(true, recordByGetAll.get('SomeBoolean__c')); // fails (null)
system.assertEquals(true, recordByGetInstance.get('SomeBoolean__c')); // fails (null)

Should I report this as a bug? I am pretty sure this just stopped working, and that it should work. Has anyone else run into this issue?

  • 3
    Totally sounds like a bug. Commented Jun 20, 2014 at 22:23
  • 1
    For what it is worth, I wasn't able to reproduce this using a list custom setting with a string field. Is it just this one boolean field? Commented Jun 21, 2014 at 8:53
  • Yes, we we have only run into this problem with Boolean fields. We have a large matrix of checkbox fields in list custom settings and some of the checkboxes read null unless they are queried for. I wish I could decipher a pattern to it all.
    – Adrian Larson
    Commented Jun 24, 2014 at 23:44
  • This sounds an awful lot like the whole checkbox initialization issue to me. We've notice that for any checkbox on custom objects that for whatever reason when initialized its null and doesn't reflect true/false until its been interacted with. Related perhaps? You could try writing some anonymous apex to loop over them and ding each one to get them initialized... Commented Jul 14, 2014 at 22:00

1 Answer 1


Looks like conversion problem.
Try doing this:

system.assertEquals(true, Boolean.valueOf(recordByGetAll.get('SomeBoolean__c')));
  • LaceySnr is right. The get function returns Object versus an explicit type. You need to cast it to be able to compare it to a boolean or any other type.
    – Brent
    Commented Sep 25, 2014 at 3:03

You must log in to answer this question.

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