Using Custom Settings in Salesforce
In Salesforce, both developer and administrator have made custom apps. Developers have used appexchange to upload packages. Custome Apps uses 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. The main problem we face is accessibility. Many users don’t have proper access to those objects so the app will work as we are expecting. To resolve this problem Salesforce has provided the custom setting. So we will start to understand the custom setting.
Custom Settings are similar to custom objects in salesforce and it has OWD (Organisation wide default) access.In custom setting data is added in the similar way as we add in the custom object using Apex code or by creating the new record. We can also associate some data with a profile or specific user. There are two types of custom settings List and Hierarchy.
How to create a custom setting in salesforce. Following are the steps : 1. Setup -> Custom Settings -> New.
2. 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.
Types of Custom Settings in Salesforce :
There are two types of custom settings.
1. List Custom Settings :In List Custom Settings, it provides a reusable set of static data which can be used across the organization. Data is available organization-wide and list custom setting does not vary with user or profile. We don’t have to use SOQL queries that count against governer limits.
Example: Catalog Numbers for products, International dialing prefixes.
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);
2. Hierarchy Custom Settings :In Hierarchy Custom Setting, it uses a hierarchical logic that lets you personalize setting for specific profiles or users. This hierarchy logic checks the profile, organization and user setting for the current user and returns the related value associated with that profile.
The getOrgDefaults() method to return the dataset values for the organization level.
CustomSettingName__c hierarchySetting = CustomSettingName__c.getOrgDefaults();
The getInstance() 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);
So it was all about the custom setting in salesforce.