Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Custom Settings
There are two types of custom settings.
- List Custom Settings: A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it. Data in list settings doesn’t vary with profile or user, but is available organization-wide. Examples of list data include two-letter state abbreviations, international dialing prefixes, and catalog numbers for products. Because the data is cached, access is low-cost and efficient: you don't have to use SOQL queries that count against your governor limits.
- HierarchyCustom Settings: A type of custom setting that 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.
To get custom setting data set record based on the lowest level fields defined in the hierarchy, use the getinstance() instance method for hierarchy custom settings.
The following examples illustrate how you can use custom settings.
- A shipping application requires users to fill in the country codes for international deliveries. By creating a list setting of all country codes, users have quick access to this data without needing to query the database.
- An application displays a map of account locations, the best route to take, and traffic conditions. This information is useful for sales reps, but account executives only want to see account locations. By creating a hierarchy setting with custom checkbox fields for route and traffic, you can enable this data for just the “Sales Rep” profile.
You can create a custom setting in the Salesforce user interface: from Setup, enter Custom Settings in the Quick Find box, then select Custom Settings. After creating a custom setting and you’ve added fields, provide data to your custom setting by clicking Manage from the detail page. Identify each data set with a name.
| Data Set Name | Country Code Field Value |
| United States | USA |
| Canada | CAN |
| United Kingdom | GBR |
Accessing a List Custom Setting
1Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();1CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);Accessing a Hierarchy Custom Setting
1CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();1CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);