Salesforce Custom Setting

Custom Setting

Use custom settings to create and manage custom data at the organization, profile, and user levels. Custom settings data is stored in the application cache. This means you can access it efficiently, without the cost of repeated queries. Custom settings data can be used by formula fields, Visualforce, Apex, and the Web Services API.

The concept of custom settings is similar to custom objects. We have to create our own custom settings similar to creating custom objects. Custom settings allow application developers to create custom sets of data, as well as associate custom data for the organization.

Application cache allows for efficient access to custom settings data without repeatedly querying the database. A formula field, a validation rule, a flow, an Apex query, and a SOAP API could be used with this data.

Custom setting is two types

  1. List custom setting
  2. Hierarchy Custom setting

List Custom Setting

An application-level list defines the data used in applications, like country codes or state abbreviations, and makes it easy to share and access static data across your organization. Putting certain data in a list custom setting streamlines access to the data if it is frequently used within your application. List settings do not vary based on user or profile but are available to all users.

List Custom Setting

Hierarchy Custom setting:

Based on hierarchical logic, it can be customized for specific profiles or users. Based on the current user’s organization, profile, and settings, hierarchy logic returns the most specific or lowest value.

Hierarchy Custom setting:

Access Custom Settings with Code

Formula Fields

It is not possible to use formula fields for list custom settings; they only work for hierarchy custom settings.

{!$Setup.CustomSettingName__c.CustomFieldName__c}

Apex

Apex can access both types of custom settings.

Example Custom Settings for Lists

If you are adding data to a custom setting, name each set so that you can distinguish it from the others. The following returns custom setting data as a map. The getAll method returns values for all custom fields associated with the list setting.

Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();

The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with list and hierarchy custom settings, using different parameters.

CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);

Example for Hierarchy Custom Settings

The following example uses the getOrgDefaults method to return the data set values for the organization level:

CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();

The following example uses the getInstance method to return the data set values for the specified profile. The getInstance method can also be used with a user ID.

CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ranbir Kumar Das

Ranbir Kumar Das

260 Followers

I M Believer, Helper, Chaser, Thinker, Rich, Explorer, Prayer, Boss, Freedom, Fearless, Investor, Faith, Creator, trillionaire, CSM, Salesforce certified