Site icon WedgeCommerce

Basics of Custom Settings

Banner

Custom Setting in Salesforce is similar to a custom object. It enables the developer to create a custom set of data and apex classes, formula field, flows, can use this data. Custom Setting data are stored in the cache. For Custom Settings, there is no need to use SOQL queries that counts against Governor Limits.

 

Few Reasons to use Custom Settings-

 

Types of Custom Setting:

From Salesforce Spring 18 release – list custom settings option is grayed out. However, we can simply enable it.

Go to Setup->Data Management->Schema Settings and Enable “Manage List Custom Settings Type”

 

How to Create Custom settings:

 

Setup -> Develop -> Custom Settings -> New -> For Label “Country Code” and for Object “Country_Code” and Save.

 

After you define custom settings, add fields to them. The custom fields contain the data used by the custom setting.

After creating a custom setting and adding fields, you can add records, then use the values in these records in your Apex code and validation rules. To create records –

 

Accessing a List Custom Setting: –

If we know the name of Custom Setting. Name like ‘Canada’ then we can use the getValues() method.

Custom_Setting_Name__c record = Custom_Setting_Name__c.getValues(data_set_name);

List<Custom_Setting_Name__c> customList = Custom_Setting_Name__c.getAll().values();

 

Accessing a Hierarchy Custom Setting: –

Custom_Setting_Name__c cs = Custom_Setting_Name__c.getOrgDefaults();

Custom_Setting_Name__c cs = Custom_Setting_Name__c.getInstance(Profile_ID);

Custom_Setting_Name__c cs = Custom_Setting_Name__c.getInstance(User_ID);

 

Exit mobile version