In Salesforce, both developer and administrator create Custom Apps. However, developers have created the apps to upload packages on AppExchange.
Custom Apps use custom setting for that object, variables which will be used. We can store them by creating any other object and can use it to store those settings as like records. But the main problem you face here is accessibility. Many users don’t have proper access to those objects so the app will not work as expected.
So Salesforce has provided “Custom Settings” as a solution for this issue.
So What are Custom Settings?
Custom Settings are similar to custom objects in salesforce but also have OWD Access (Org Wide Default). It enables application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user.
In custom setting, we add data in the similar way as we add in the custom object using by creating the new record or Apex Code. We can also use custom settings in formula fields, Web Services API and validation rules.
How to create a custom setting in salesforce. Following are the steps :
1. Setup -> Custom Settings -> New.
After Spring’18 release, Users are unable to create new List Type Custom Setting. They can only select Hierarchy as an option, List option is greyed out.
So to enable List Type Custom Settings :
Go to Setup->Data Management->Schema Settings and Enable “Manage List Custom Settings Type”.
Types of Custom Settings in Salesforce :
- In Custom Setting Definition-
- Label: Enter the label displayed.
- Object: Name used when the custom setting is referenced by formula fields, Apex, or the Force.com Web Services API.
- Setting Type: Choose the type of List or Hierarchy.
- Visibility: Choose visibility Protected or Public.3. Click on Save button.
There are two types of Custom Settings:
- List Custom Settings: In List Custom Settings, it provides a reusable set of static data that can be used across the organization. It does not vary with user or profile and data is available org-wide. Here, we do not have to use SOQL queries that count against governer limits.
: We could use several configurations to hold the credentials for a callout (Web Service) so that we can swap the end-points setting for various environment.
Accessing a List Custom Setting:
() method returns values for all custom fields associated with List Custom Setting.
Map<String_dataset_name, CustomSettingName__c> listSetting = CustomSettingName__c.getAll();
If we use field values associated with the specified dataset then getValue
() method is used.
CustomSettingName__c listSetting = CustomSettingName__c.getValues(data_set_name);
- Hierarchy Custom Settings: Hierarchy Custom Settings uses a hierarchical logic, which allows us to personalize setting for specific profiles or users. This hierarchy logic checks for the profile, organization and user settings for the current user and returns the related value associated with that profile.
These settings provide the functionality of a switch that we can use as ON or OFF to disable Integrations, Triggers, Workflow Rules, Assignment Rules and Validation Rules for all the users, specific profiles or individual users. This is only possible when we use hierarchical custom settings with a checkbox field to control our system functions, but we could also use it to control internal debugging log levels.
Accessing a Hierarchy Custom Setting :
() method to return the dataset values for the organization level.
CustomSettingName__c hierarchySetting = CustomSettingName__c.getOrgDefaults();
() method to return dataset value for the specific profile. It can be used with a User ID.
CustomSettingName__c hierarchySetting = CustomSettingName__c.getInstance(Profile_ID);