{"id":5100,"date":"2025-12-17T07:25:00","date_gmt":"2025-12-17T07:25:00","guid":{"rendered":"https:\/\/differenzforce.com\/blog\/?p=5100"},"modified":"2025-12-16T10:11:26","modified_gmt":"2025-12-16T10:11:26","slug":"salesforce-custom-settings","status":"publish","type":"post","link":"https:\/\/differenzforce.com\/blog\/salesforce-custom-settings\/","title":{"rendered":"Salesforce Custom Settings"},"content":{"rendered":"\n<p>Salesforce Custom Settings are essential for managing configuration data in Salesforce. They allow businesses to store organization-wide and user-specific data, improving access speed and overall system performance.<\/p>\n\n\n\n<p>At Differenz Force, we help businesses set up and manage Salesforce Custom Settings. Our expertise optimizes your Salesforce platform, reduces query times, and improves overall system performance. Custom Settings make your Salesforce environment more scalable and efficient.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-1\">Meaning of Salesforce Custom Settings<\/h2>\n\n\n\n<p>Salesforce Custom Settings are a special type of custom object that allow you to store configuration data. Unlike regular objects, Custom Settings are designed to provide easy access to information without complex queries, making them a valuable tool for optimizing performance.<\/p>\n\n\n\n<p>They are used to store data that is needed frequently, such as global configurations, user-specific settings, or other settings that must be accessed across Salesforce applications. This data is easily accessible through Apex code or formulas and can reduce the number of SOQL queries, ultimately improving the speed and efficiency of your Salesforce system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-2\">Types of Salesforce Custom Settings<\/h2>\n\n\n\n<p>Salesforce offers two main types of Custom Settings: List Custom Settings and Hierarchy Custom Settings. Each serves a different purpose depending on the type of data you are storing and the specific needs of your Salesforce environment.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. List Custom Settings<\/h4>\n\n\n\n<p>List Custom Settings are used to store data that remains constant across the entire organization. This type is ideal for storing configuration values that apply universally, such as global app settings. Data stored in List Custom Settings is accessible to all users without customization for individual profiles or users.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Use Cases:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store global app configurations.<\/li>\n\n\n\n<li>Ideal for shared system settings.<\/li>\n\n\n\n<li>No user-specific customization required.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Hierarchy Custom Settings<\/h4>\n\n\n\n<p>Hierarchy Custom Settings allow data to be customized based on user profiles or individual users. This means you can set different values for various teams or users within the organization. For example, you might assign different settings to the sales team, the customer support team, or even specific settings to individual users.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Use Cases:<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Store user-specific or profile-specific data.<\/li>\n\n\n\n<li>Ideal for personalized configuration settings.<\/li>\n\n\n\n<li>Supports different settings for each user or profile.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-3\">Accessing Salesforce Custom Settings in Apex<\/h2>\n\n\n\n<p>Salesforce Custom Settings provide a powerful way to store application-level or user-level configuration data. They help control logic, manage settings, and reduce hardcoded values. You can access Custom Settings in Apex using built-in methods such as getAll(), getValues(), and getInstance().<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Types of Salesforce Custom Settings<\/h4>\n\n\n\n<p>Salesforce offers two types of custom settings:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">List Custom Settings<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Work like custom objects.<\/li>\n\n\n\n<li>Store global\/static data shared by all users.<\/li>\n\n\n\n<li>Accessible by record name (key).<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Hierarchy Custom Settings<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Allow different values based on:\n<ul class=\"wp-block-list\">\n<li>Organization level<\/li>\n\n\n\n<li>Profile leve<\/li>\n\n\n\n<li>User level<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Useful for role-based or user-specific preferences.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Accessing List Custom Settings<\/h4>\n\n\n\n<p>List Custom Settings can be retrieved using methods like&nbsp;getAll()&nbsp;and&nbsp;getValues().<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">a) Fetching All Records<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>Map&nbsp;courses = Course_Settings__c.getAll();<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Retrieves all records stored in the&nbsp;Course_Settings__c&nbsp;setting.<\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">b) Fetching a Specific Record by Name<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>Course_Settings__c course = Course_Settings__c.getValues(&#8216;Physics&#8217;);<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Retrieves the record where the name is&nbsp;&#8216;Physics&#8217;.<\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">c) Using getValues() for All or Specific Keys<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>\/\/ All records as a map<\/p>\n\n\n\n<p>Map&nbsp;settingsMap =<br>MyCustomSetting__c.getValues();<\/p>\n\n\n\n<p>\/\/ Specific keys<\/p>\n\n\n\n<p>List&nbsp;keys = new List{&#8216;Key1&#8217;, &#8216;Key2&#8217;};<\/p>\n\n\n\n<p>List&nbsp;selectedSettings =<br>MyCustomSetting__c.getValues(keys);<\/p>\n\n\n\n<p>Replace&nbsp;MyCustomSetting__c&nbsp;with your actual custom setting API name.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. Accessing Hierarchy Custom Settings<\/h4>\n\n\n\n<p>Hierarchy settings allow Salesforce to return different values depending on the user, profile, or org-level settings.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">a) Fetching Organization-Wide Defaults<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>User_Settings__c orgDefaults = User_Settings__c.getOrgDefaults();<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Returns the default (global) values for the org.<\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">b) Fetching Settings for a Specific Profile<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>User_Settings__c profileSettings =<br>User_Settings__c.getInstance(Profile_ID);<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace&nbsp;Profile_ID&nbsp;with the actual Profile ID.<\/li>\n\n\n\n<li>Returns the settings for that profile.<\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">c) Fetching Settings for a Specific User<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>User_Settings__c userSettings = User_Settings__c.getInstance(User_ID);<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Replace&nbsp;User_ID&nbsp;with the actual User ID.<\/li>\n\n\n\n<li>Returns settings applied to that user.<\/li>\n<\/ul>\n\n\n\n<h6 class=\"wp-block-heading\">d) Fetching Current User&#8217;s Settings<\/h6>\n\n\n\n<p>apex<\/p>\n\n\n\n<p>MyCustomSetting__c currentUserSetting =<br>MyCustomSetting__c.getInstance(UserInfo.getUserId());<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Useful for user-specific configurations.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-4\">Key Considerations<\/h2>\n\n\n\n<p>A typical setup for Salesforce DevOps may include:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Feature<\/th><th>Description<\/th><\/tr><tr><td>Performance<\/td><td>Custom Settings are cached in memory for fast access (no SOQL needed).<\/td><\/tr><tr><td>Privacy &amp; Access<\/td><td>Protected settings in managed packages can&#8217;t be accessed by subscriber orgs.<\/td><\/tr><tr><td>Schema Setting Option<\/td><td>Enable &#8220;Manage List Custom Settings Type&#8221; in Setup if needed.<\/td><\/tr><tr><td>Deployment Caution<\/td><td>Custom Setting data doesn\u2019t deploy with change sets; use data loader or scripts.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-5\">Code Summary \u2013 Quick Reference Table<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Use Case<\/th><th>Apex Code<\/th><\/tr><tr><td>All List Records<\/td><td><code>Map&lt;String, MySetting__c&gt; map = MySetting__c.getAll();<\/code><\/td><\/tr><tr><td>Specific List Record<\/td><td><code>MySetting__c setting = MySetting__c.getValues('RecordName');<\/code><\/td><\/tr><tr><td>Multiple Specific Keys<\/td><td><code>List&lt;MySetting__c&gt; list = MySetting__c.getValues(keys);<\/code><\/td><\/tr><tr><td>Org-Wide Default (Hierarchy)<\/td><td><code>MySetting__c default = MySetting__c.getOrgDefaults();<\/code><\/td><\/tr><tr><td>Profile-Level Hierarchy Setting<\/td><td><code>MySetting__c profileSetting = MySetting__c.getInstance(ProfileId);<\/code><\/td><\/tr><tr><td>User-Level Hierarchy Setting<\/td><td><code>MySetting__c userSetting = MySetting__c.getInstance(UserId);<\/code><\/td><\/tr><tr><td>Current User Hierarchy Setting<\/td><td><code>MySetting__c me = MySetting__c.getInstance(UserInfo.getUserId());<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-6\">Limitations of Salesforce Custom Settings<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Migration Restriction<\/strong>: Cannot be migrated between environments using change sets; requires manual recreation or data deployment tools.<\/li>\n\n\n\n<li><strong>Governor Limits<\/strong>: Counts toward Salesforce governor limits, especially in Apex transactions.<\/li>\n\n\n\n<li><strong>No Triggers or Validation Rules<\/strong>: Cannot have triggers, workflows, or validation rules applied.<\/li>\n\n\n\n<li><strong>Limited API Access<\/strong>: Cannot be accessed directly through the Salesforce API.<\/li>\n\n\n\n<li><strong>SOQL Alternative Required<\/strong>: Does not support SOQL queries, requiring Apex methods such as getAll and getInstance.<\/li>\n\n\n\n<li><strong>Not for Complex Data Structures<\/strong>: Cannot create relationships with standard or custom objects.<\/li>\n\n\n\n<li><strong>Limited Field Types<\/strong>: Does not support certain field types, such as lookup or formula fields.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"list-item-7\">Best Practices for Using Salesforce Custom Settings<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use for Configuration Data<\/strong> \u2013 Avoid using custom objects for settings to reduce SOQL queries.<\/li>\n\n\n\n<li><strong>Use Hierarchy Custom Settings for User-Specific Data<\/strong> \u2013 Store different settings for users or profiles.<\/li>\n\n\n\n<li><strong>Keep Data Small<\/strong> \u2013 Large datasets are not supported, so store only necessary information.<\/li>\n\n\n\n<li><strong>Use Apex Methods for Fast Access<\/strong> \u2013 Use getAll(), getValues(), and getInstance() instead of SOQL.<\/li>\n\n\n\n<li><strong>Update Regularly<\/strong> \u2013 Review and remove outdated settings to keep data relevant.<\/li>\n\n\n\n<li><strong>Avoid Using for Large Data Processing<\/strong> \u2013 Not suitable for bulk operations or frequently changing data.<\/li>\n\n\n\n<li><strong>Do Not Use for Relationships<\/strong> \u2013 Custom Settings do not support relationships with other objects.<\/li>\n\n\n\n<li><strong>Secure Sensitive Data<\/strong> \u2013 Custom Settings do not provide field-level security, so avoid storing confidential information.<\/li>\n\n\n\n<li><strong>Use List Custom Settings for Global Values<\/strong> \u2013 Store organization-wide constants efficiently.<\/li>\n\n\n\n<li><strong>Consider Custom Metadata for Deployment Needs<\/strong> \u2013 If you need to migrate settings, <a href=\"https:\/\/differenzforce.com\/blog\/custom-metadata-in-salesforce\/\">Salesforce Custom Metadata<\/a> may be a better option.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Salesforce Custom Settings are essential for managing configuration data in Salesforce. They allow businesses to store organization-wide and user-specific data, improving access speed and overall system performance. At Differenz Force, we help businesses set up and manage Salesforce Custom Settings. Our expertise optimizes your Salesforce platform, reduces query times, and improves overall system performance. Custom [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":5706,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[223],"tags":[],"class_list":["post-5100","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-salesforce-development"],"rank_math_description":"Learn how to access and use Salesforce Custom Settings in Apex. Understand the difference between List and Hierarchy Custom Settings.","category_names":["Salesforce Development"],"author_name":"Shyam Agarwal","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/posts\/5100","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/comments?post=5100"}],"version-history":[{"count":3,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/posts\/5100\/revisions"}],"predecessor-version":[{"id":6243,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/posts\/5100\/revisions\/6243"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/media\/5706"}],"wp:attachment":[{"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/media?parent=5100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/categories?post=5100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/differenzforce.com\/blog\/wp-json\/wp\/v2\/tags?post=5100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}