1

We have a custom setting with multiple fields which we use in validation rules and flows. One of the fields in the setting is "Validation Enabled" which we use to disable validation rules to allow initial import of test data in scratch orgs.

When we create a scratch org, if we try to upload certain data which doesn't respect validation rules, validation fails even if the custom settings org defaults has not been created yet on the org, because Validation Enabled default value is true

Additionally

MySettings.getOrgDefaults() 

does not return null even if the instance has not been created, suggesting somehow Salesforce there is a record for the defaults even before you create it on the UI. On the other side, when we access the settings from the flow through a "Get Record" that step completes with "Failed to find record", as if a default instance is not existing in the org.

Is it a particule, or is it a wave? Is it Metadata or is it an sObject?

1 Answer 1

3

According to the documentation, neither getOrgDefaults() nor getInstance() does return null in since Spring' 12.

In case if there are no custom settings record, both will return an object, empty one in first case and with only populated SetupOwnerId in second case, assuming that there are no custom setting records created in the environment.

Also take into an account that if API version of your class is less than v22, then given methods will return null

In your scenario, you can improve your apex code, but doing extra check if returned custom settings (by getOrgDefaults(), because getInstance() does not return record id) record has an ID specified, and if so - then record is actually inserted in salesforce, and it might need to be taken into account.

Documentation:

3
  • Very useful! Thanks a lot for answering. What do you think about the awkward behaviour in flows ? It seems that the flow interpreter has a different behaviour with respect to getOrgDefaults
    – Edmondo
    May 20, 2019 at 20:26
  • indeed it does. Flow getRecord behaves pretty much exactly as a [SELECT Id FROM CustomSettings__c], so it might return null in case if there are no custom setting record inserted.
    – kurunve
    May 20, 2019 at 20:28
  • I think there is a problem with process builders and $setup.my_custom_setting, since it tends to act like an "empty" custom setting
    – Edmondo
    Jul 10, 2019 at 10:37

You must log in to answer this question.

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