I've been looking at some older code and trying to figure out why it works.

They have something like this:

List_Custom_Setting__c settings = List_Custom_Setting__c.getInstance();

The API doc does not mention a List custom setting getinstance() method without parameters, so it's curious.

settings above is filled with the the "first" value in the custom setting. As far as I can tell, which row it returns is undefined, but there is only ever one record in this List custom setting, so there's no issue. (Although, one could argue that perhaps a Hierarchy custom setting should have been used in this case.)

So I attempted to replicate this above statement in the Developer Console:

System.debug('1: '+List_Custom_Setting__c.getInstance());

and I received

1: List_Custom_Setting__c:{SetupOwnerId=005XXX}

whereas the code receives

1: List_Custom_Setting__c:{Id=a0mXXX,
IsDeleted=false, Name=Steve Test, SetupOwnerId=00DXXX, 
CreatedDate=2015-07-14 13:13:57, CreatedById=005XXX, 
LastModifiedDate=2016-08-10 22:05:16, LastModifiedById=005XXX, 
SystemModstamp=2016-08-10 22:05:16, Custom_Field__c=test}

So the old code uses v20.0. At some point between v20.0 and v37.0 the behavior of {List Custom Setting}.getInstance() changed. I was able to reproduce the behavior in the Workbench selecting version 20.0 and selecting Apex Execute from the Utilities menu.

  • See also this known issue, which is probably related. I believe there was a change somewhere between version 27.0 and 32.0, but I can't seem to find the notes. – sfdcfox Aug 10 '16 at 22:55
  • getInstance(null) is what this refers to, not getInstance(). May be the same result, though. – Ray Dehler Aug 10 '16 at 23:25

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.