Activity Forums Salesforce® Discussions Custom Setting in Salesforce and Their Importance

  • chanchal kumar

    Member
    September 10, 2018 at 10:17 am

    Hello Avnish,

    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.

  • Parul

    Member
    September 10, 2018 at 11:27 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.

    Importance of Custom Settings
    Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits to ensure that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds the limit then exception cannot be handled. When we need data we query from object and display, if we query multiple time there is chance of hitting governing limit. So to avoid governing limit we use custom setting. It allows us to store set of data and access it without querying it from apex.

    Steps to create a custom setting in the Salesforce user interface:

    Setup, enter Custom Settings in the Quick Find box, then select Custom Settings.

     

     

    Thanks.

  • shariq

    Member
    September 10, 2018 at 12:42 pm

    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. 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.

    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);

    Hope this helps!

  • madhulika shah

    Member
    September 10, 2018 at 12:46 pm

    Hi Avnish,

    Custom Settings are essentially custom objects that are exposed in the applications cache and are accessible via their own API.

    There are two important aspects of Custom Settings.
    1. They act like an object but cached in memory so they do not require database connections. so if you are quering custom settings then you do not need to worry about too many Soql errors also no database timeout errors. Basically you are saving your database query governing limits for other purposes.

    2. Custom Settings does not count against total objects. It means that you can use Custom Settings to hold some Administrative parameters or commonly consumed data to be used by your Apex or Visualforce logic instead of creating a new object. The best use of new object will be for holding large amount of data.

Log In to reply.

Popular Salesforce Blogs