0

I have a hierarchical custom setting called Test_Custom_Setting__c and I have field in there called Time_Delay__c set to the default value of 5 and also the Organizational defaults for this field is set to the value of 5 as well. The previous value for this field was 15.

Now I have used this custom setting field in a case formula field like below -

Date__c + (60-$Setup.Test_Custom_Setting__c .Time_Delay__c )/1440

And also tried checking the value for the custom field through apex-

Test_Custom_Setting__c tc = Test_Custom_Setting__c .getInstance();
Decimal def = tc.Time_Delay__c ;
System.debug(def);

Why is the formula field and the apex code taking the old value of the custom setting which is 15 and not the new value in both the scenarios mentioned above?

Please advise.

9
  • When you say The previous value for this field was 15. can you show or describe how/when this took place related to when the formula or apex reads occurred?
    – Mark Pond
    Commented Aug 4, 2022 at 19:59
  • @MarkPond I just changed it manually based off business requirements. Even after the change it just takes the old value into the calculation on the formula field.
    – sumchans
    Commented Aug 4, 2022 at 20:01
  • When you say default value, do you literally mean the field definitions default or do you mean a value set in the org level and other settings record?
    – Phil W
    Commented Aug 4, 2022 at 20:10
  • @PhilW I meant the field definitions default value. This was working well with the previous setting, but now business needs a change to that value.
    – sumchans
    Commented Aug 4, 2022 at 20:11
  • 2
    by definition, hierarchical custom settings use the user's value if present, else the profile's value if present, else the org value. Use custom metadata for org defaults
    – cropredy
    Commented Aug 4, 2022 at 20:56

1 Answer 1

2

By definition, hierarchical custom settings ...

Hierarchy—Uses a built-in hierarchical logic that lets you personalize settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or lowest, value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.

If you always want to use an org-level setting - make that setting a field in Custom Metadata - which is also accessible in formulas

Date__c + (60-$CustomMetadata.DateSettings__mdt.Test_Custom_Setting__c.Time_Delay__c )/1440

where

  • DateSettings__mdt is the name of the custom metadata Sobject
  • Test_Custom_Setting__c is the developerName of a specific record in the custom metadata Time_Delay__c is a field in the chosen record

Of course, you can use different names than the ones I chose based on your application

You must log in to answer this question.

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