How to use Custom setting in Salesforce?
How to use Custom setting in Salesforce?
In this post we are going to discuss how to create a custom setting and how to use the Custom setting API.
To know more about the custom setting kindly go through the post here.
To create a Custom setting follow the below steps:-
- Go to setup and click on the Quick find / search input box and type ‘custom settings’.
- Click on custom setting and then on the create custom setting page click on new button.
- This will open New Custom Setting Definition page where we have to provide the custom setting with a label, Object name, its type (list/Hierarchy), visibility and its description.
- After filling all the information on the definition page click on save button.
- This will take you to the custom setting definition detail page. On this page all the system defined and the related information of the custom setting is displayed.
- On this page you can add new custom fields to the Custom setting similar to the Custom object, but data type of the new fields are limited as shown below.
- After selecting the data type remaining steps of creating the field is similar to the custom objects field creation.
Once you have created all the required fields the custom setting detail page looks something as below.
Once you have completed creating the custom setting, then it is the time to enter some data in the custom setting datasets. To insert the data we need to click on the manage button on the custom setting detail page, as shown below.
Clicking on the manage button, redirects to the dataset detail page where we can add. Delete and edit records of custom settings.
On this page, to create a new record click on the new button and enter the value in the fields and click on save as shown below.
Once you have desired number of records I the custom setting. We can use the Custom setting API’s to fetch the records.
Below I have written a class which access the custom settings without making a SOQL call to database and returns a map of string and custom setting records.
public class CustomSettingCls {
public map<String, IVL_Offline_document__c> fetchDocMapFromCustomSetting(String profileName){
map<String, IVL_Offline_document__c> mcs = new map<String, IVL_Offline_document__c>();
list<IVL_Offline_document__c> lcs = IVL_Offline_document__c.getall().values();
for(IVL_Offline_document__c recordCS : lcs){
if(recordCS.IVL_Profile_Name__c == profileName){
mcs.put(recordCS.Name, recordCS);
}
}
return mcs;
}
}
Also, Have a look at the below resources:
Also, Have a look at the below learning resources:
-
SOQL (Salesforce Object Query Language)
-
Apex Trigger Best Practices and the Trigger Framework
-
Salesforce Interview Question and Answers Part 2
-
Salesforce Interview Questions on Test Class
-
Salesforce-lightning-interview-questions-2018
It would be great if you can post a few more use cases of custom settings