Setting up a Hierarchy Custom Setting involves creating the setting metadata, adding fields, populating values at each hierarchy level, and accessing the values in Apex. The steps below cover the full setup.
- Create the Custom Setting
Setup > Custom Settings > New. Name it descriptively (FeatureFlag__c), set Setting Type to Hierarchy, choose Public or Protected visibility. Save.
- Add fields
From the Custom Setting detail, add fields (Checkbox for feature flags, Text for endpoint URLs). Field types are limited; complex types require a custom object instead.
- Set the org-wide default
From the Custom Setting > Manage, click New (in the organization section). Enter values for each field. Save. This is what every user sees absent any override.
- Add profile-level overrides
Still in Manage, click New (in the profile section). Pick the profile, enter values. Save. Users with that profile now see the override instead of the org default.
- Add per-user overrides if needed
Add specific user overrides only for genuine per-user needs. Most settings do not need this level.
- Access from Apex
In Apex, call MySetting__c.getInstance() to get the running-user value with full hierarchy lookup. Use getOrgDefaults() to bypass hierarchy and read just the org default.
- Plan deployment
The setting schema deploys through changesets. The data (org defaults, profile overrides) does not. Write a post-deployment Apex script or use Data Loader to populate values in each environment.
The base value every user sees absent any override. Set first.
Override for a specific profile. Takes precedence over org default.
Override for a specific user. Highest precedence; takes precedence over profile and org.
Accessible from any Apex code. The standard choice for application settings.
Accessible only from Apex within the same namespace. For managed packages.
- Custom Setting data does not deploy through changesets. The schema does; values must be populated in each environment separately. Plan deployment scripts.
- Custom Setting data is capped at 10 MB total across all settings. Large or many settings hit the cap; plan storage carefully.
- Updates take a few seconds to propagate across all servers. Code that updates and immediately reads may return stale values briefly.
- Per-user overrides should be rare. Reserve for personal preferences; for most settings, profile overrides are sufficient and easier to maintain.
- Custom Settings cannot have validation rules, triggers, or sharing rules. For configuration needing those, use a custom object instead.