Activity Forums Salesforce® Discussions What are the types of custom settings in Salesforce?

  • Manpreet

    Member
    April 20, 2017 at 1:39 pm

    What are the types of custom settings in Salesforce? What is the advantage of using custom settings?

  • Suraj

    Member
    April 20, 2017 at 1:58 pm

    Hi Manpreet,

    Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user.

    Custom Setting enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, Apex, and the Web services API. Custom Setting are of 2 types Hierarchy Custom Settings and List Custom Setting.

  • Saurabh

    Member
    April 20, 2017 at 2:18 pm

    Hi Manpreet

    Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, flows, Apex, and the SOAP API.

    There are two types of custom settings:

    List Custom Settings
    A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it. Data in list settings does not vary with profile or user, but is available organization-wide. Examples of list data include two-letter state abbreviations, international dialing prefixes, and catalog numbers for products. Because the data is cached, access is low-cost and efficient: you don't have to use SOQL queries that count against your governor limits.

    Hierarchy Custom Settings
    A type of custom setting that uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.

    All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. However, querying custom settings data using Standard Object Query Language (SOQL) doesn't make use of the application cache and is similar to querying a custom object. To benefit from caching, use other methods for accessing custom settings data such as the Apex Custom Settings methods.

    Hope it may helps

  • Louis

    Member
    May 16, 2017 at 9:58 am

    Hi Manpreet,

    Custom settings are similar to custom objects, where we can create custom object where can create custom field, store our data. Custom Settings are essentially custom objects that are exposed in the applications cache and are accessible via their own API.

    Custom settings are of two types:

    1.      List custom settings

    2.      Hierarchy custom settings

    List Custom Settings

    Here can store our data and display that data without using soql.If we are using soql to fetch or display same record for multiple times it might  hit governing limit ,to avoid that we can use list custom setting.

    I have object named student__c where I need to fetch record on frequently basis. I am displaying record using soql.

    List<student__c>stu= [select name, phone__c ,email__c, mark__c  from student__c];

    Salesforce runs Multi-tenant environment, so there is chances of hitting governor limit in salesforce,

    If I store that in custom object I can fetch withoutusing soql.we can fetch data using custom setting methods,

    Here customsetting object name is student__c

    Public class Studentexample{

    Public List<student__c>stuList{set;get;}

    Public Studentexample(){

    stuList= new list<student __c>();

    Map<string,student__c>Mapstu=stu.getAll();

    stuList=mapstu.values();

    }

    }

    We can display that record in visualforce page

    <apex:pageblocktable value={“!stuList”} var=”s”>

    <apex:colum value=”{!s.name}”/>

    <apex:colum value=”{!s.phone__c}”/>

    <apex:colum value=”{!s.Mark__c}”/>

    <apex:colum value=”{!s.Email__c}”/>

    </apex:pageblocktable>

    Hierarchy Custom Settings

    This type of   custom setting that help to customize settings for specific profiles or users. The hierarchy logic checks the organization, profile, and users. We can override profile or user organization per wide. We canby-pass validation to a particular profile or user.

    Object name is  Hierarchy Settingsexample__c

    Hierarchy Settingsexample__c Hcs=HierarchySettingsexample __c.getInstance();

    We can choose user by this method userInfo.getUserId();

    We can choose profile by this method userinfo.getprofileid();

    • This reply was modified 4 years, 6 months ago by  Louis.
  • shariq

    Member
    September 18, 2018 at 10:35 am

    Hi,

    Custom Settings are persisted in the database. However they're also cached.

    When using the cache methods Custom_setting__c.getAll(), .getInstance(), and .getValues(), Salesforce uses the cached values.

    If you use a SOQL query (SELECT id, name, etc FROM Custom_setting__c) to get data for a custom setting, Salesforce queries the database and uses one of your allotted queries.

    NOTE: I've found that you can only consistently modify a custom setting if you use a SOQL query to load it. Loading via a cache method does not load the custom setting's id which is required to update the custom setting.

    Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user.

    Accessing a Hierarchy Custom Setting
    The following example uses the getOrgDefaults method to return the data set values for the organization level:

    CustomSettingName__c mc = CustomSettingName__c.getOrgDefaults();
    The following example uses the getInstance method to return the data set values for the specified profile. The getInstancemethod can also be used with a user ID.

    CustomSettingName__c mc = CustomSettingName__c.getInstance(Profile_ID);

    Accessing a List Custom Setting
    The following example returns a map of custom settings data. The getAll method returns values for all custom fields associated with the list setting.

    Map<String_dataset_name, CustomSettingName__c> mcs = CustomSettingName__c.getAll();
    The following example uses the getValues method to return all the field values associated with the specified data set. This method can be used with both list and hierarchy custom settings, using different parameters.

    CustomSettingName__c mc = CustomSettingName__c.getValues(data_set_name);

  • Parul

    Member
    September 18, 2018 at 10:36 am

    HI

    Custom settings are similar to custom objects and enable application developers to create custom sets of data, as well as create and associate custom data for an organization, profile, or specific user. All custom settings data is exposed in the application cache, which enables efficient access without the cost of repeated queries to the database. This data can then be used by formula fields, validation rules, Apex, and the SOAP API.

    There are two Types of Custom settings
    List Custom Settings : A type of custom setting that provides a reusable set of static data that can be accessed across your organization. If you use a particular set of data frequently within your application, putting that data in a list custom setting streamlines access to it.

    Hierarchy Custom Settings : Hierarchy settings allow you to personalize your application for different profiles and/or users. A type of custom setting that uses a built-in hierarchical logic that lets you “personalize” settings for specific profiles or users. The hierarchy logic checks the organization, profile, and user settings for the current user and returns the most specific, or “lowest,” value. In the hierarchy, settings for an organization are overridden by profile settings, which, in turn, are overridden by user settings.

     

    Thanks

Viewing 1 - 6 of 6 posts

Log In to reply.

Popular Salesforce Blogs