Hierarchy Custom Settings
By the end of this lesson, you'll be able to:
- Explain what makes a hierarchy custom setting different from a list custom setting
- Read the effective value for the running user with getInstance()
- Identify a scenario where per-profile or per-user configuration is genuinely needed
Prerequisites: "List Custom Settings"
Three levels, one effective value
A hierarchy custom setting can define a value at the org-wide default level, again at the profile level, and again at the individual user level — Salesforce automatically resolves which one actually applies for a given user, always preferring the most specific level that has a value set.
Reading the effective value
Feature_Toggle__c toggles = Feature_Toggle__c.getInstance();
if (toggles.Enable_Beta_Dashboard__c) {
System.debug('Beta dashboard is enabled for this user.');
}
getInstance() (no arguments) returns the value that applies to the currently running user — automatically checking user-level, then profile-level, then org-default, and returning the first one actually set. Apex code never needs to manually work out which level applies.
A real scenario: staged feature rollout
Feature_Toggle__c toggles = Feature_Toggle__c.getInstance();
if (toggles.Enable_Beta_Dashboard__c) {
return buildBetaDashboard();
} else {
return buildStandardDashboard();
}
A hierarchy custom setting is exactly the right tool for a staged feature rollout: turn a feature on org-wide as the default, but override it off for one profile still being tested with, or on for one specific beta-tester user — all resolved automatically by getInstance(), with zero extra Apex logic needed to check "which level am I at."
Exercise
As a comment, explain what getInstance() returns and how it decides which level (org, profile, user) to use.
Show hint
Think about "most specific level that has a value set."
Hierarchy Custom Settings Quiz
My Notes
Log in to keep private notes on this lesson.
Questions about this lesson
No questions yet — be the first to ask.
Log in to ask a question about this lesson.
Summary
A hierarchy custom setting can have different values at the org, profile, and user level — Apex automatically resolves the most specific one that applies to the current running user.