Custom Settings in Salesforce - A Brief Guide
What is Custom Settings in Salesforce?
Custom Settings are a way for anyone to gain easier and faster access to information. It generates specific data chunks based on the user's requirements, which are saved in the application cache for faster Salesforce access.
Any data stored in custom settings will be obtained without the need for any SOQL (Salesforce Object Query Language) queries, therefore no SQL queries are required.
The similarities between custom items and settings are striking. Both of these components enable Salesforce developers to create custom data sets and associate them with the appropriate object based on the client's needs. In both custom objects and settings, users can define custom fields.
Custom settings, on the other hand, have fewer types of fields, such as:
- Checkbox
- Date/time
- Number
- Percent
- Text
- Text area
- Phone
- Currency
- URL
Don't forget to check out: How To Create Custom Settings And Custom Objects | Salesforce Developer Guide
Types of Custom Settings
- List Custom Settings
- Hierarchy Custom Settings
List Custom Settings
A sort of custom setting that creates a reusable set of static data that may be used throughout your company. If you frequently utilize a particular piece of data in your application, putting it in a list custom setting makes it easier to access. List settings data is available to all users and profiles across the company.
How to use:
- getValues(Custom_Setting_Name) method returns the instance of the Custom Setting.
If we know the name of Custom Setting. then we can use the getValues() method.
Custom_Setting_Name__c record = Custom_Setting_Name__c.getValues(data_set_name)
- Values() method returns a list of all thye custom setting
List<Custom_Setting_Name> CustomSettingList= Custom_Setting_Name__c.getAll().values();
Hierarchy Custom Settings:
A custom setting with built-in hierarchical logic that allows you to "personalize" settings for certain profiles or users. The hierarchy logic examines the current user's organization, profile, and user settings and delivers the most specific, or "lowest," value. Organizational settings are overridden by profile settings, which are overridden by user settings in the hierarchy.
Check out another amazing blog by Avinash here: How to Set Up Web-to-Lead in Salesforce | The Complete Guide
How to use:
- GetOrgDefaults() method return the dataset values of organization level.
Custom_Setting_Name csn= Custom_Setting_Name.getOrgDefaults();
- getinstance() method return the data set values for the specified profile or user.
Custom_Setting_Name csn= Custom_Setting_Name.getinstance(Profile_ID);
Custom_Setting_Name csn= Custom_Setting_Name.getinstance(User_ID);
Responses