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
JVIowaJVIowa 

Custom Setting getOrgDefaults not returning Null anymore

According to the documentation when you call getOrgDefaults on a Custom Setting it should return null if there are no Org Defaults defined.  Since the Spring 12 release this method is not returning null but instead is returning a blank object.  Try the following code from the Developer Console on a custom setting with no values defined.  This causes problems if you have code that has defaults defined in the case of the Custom Setting not being configured yet (i.e. getOrgDefaults returning NULL).

 

System.debug(YourCustomSetting__c.getOrgDefaults());

 

The debug output will look like below instead of saying Null

 

10:05:08:098 USER_DEBUG [1]|DEBUG|YourCustomSetting__c:{}

 

Has anyone else noticed this?  I am going to log a case with Developer Support as well.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
rungerrunger

The semantics changed in v.24. If you're seeing this in v.23 or earlier then, yes, please, file a case.

To get null back if there's no org-level data in v.24, I'd suggest using getValues(UserInfo.getOrganizationId())

 

A fuller description of custom settings semantics in v.24 is here:

http://thecodestuff.wordpress.com/2012/02/14/hierarchy-custom-settings-semantics-explained/

All Answers

craigmhcraigmh
rungerrunger

The semantics changed in v.24. If you're seeing this in v.23 or earlier then, yes, please, file a case.

To get null back if there's no org-level data in v.24, I'd suggest using getValues(UserInfo.getOrganizationId())

 

A fuller description of custom settings semantics in v.24 is here:

http://thecodestuff.wordpress.com/2012/02/14/hierarchy-custom-settings-semantics-explained/

This was selected as the best answer
craigmhcraigmh

Thanks for the link, Rich. The documentation should probably be updated, it seems fairly confusing.

JVIowaJVIowa

FYI, It is happening in a class marked with apiVersion 23 in the meta file.  I have changed the code to use your suggestion of getValue and passing in the Org Id, seems to be working according to the documentation.  I have logged a case with Developer support as well.

Katia HageKatia Hage

The return value of getOrgDefaults() changed starting with version 22.0 actually (and not 24). Sorry for the misleading information in the documentation. In version 21.0 null is returned but in versions 22.0 and up, an empty custom setting object is returned if no data is defined.

We'll be updating the doc with the correct info. Thanks for catching this.