Custom setting in Salesforce

Custom Setting in Salesforce

Custom setting in Salesforce 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.

We can create custom setting in salesforce for storing data similar to custom objects in salesforce but here the data is static.

Similar to custom object, we can create fields in custom setting and after creating the fields, we can click on ‘Manage’ button to add records in that custom setting. Then we can use the values in these records in our apex code, validation rules. The benefit of using custom setting instead of custom objects:

  • Data in custom setting is available in application cache, hence efficient and fast access.
  • No need to waste SOQL for fetching data from custom setting. There are some methods available in custom settings that we can use to get the data instead of SOQL.

Types of custom settings available in salesforce :

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.

Custom setting in Salesforce List

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.

Custom setting in Salesforce Hierarchy

In above screenshot, you can see that records in a particular custom setting can be created for particular profile or user. But this is not the case with List custom setting. Records in list custom setting are available for all users and profile in application.

Salesforce imposes certain limits on the amount of cached data and on custom settings:

  • The total amount of cached data allowed for your organization is the lesser of these two values:
    • 10 MB
    • 1 MB multiplied by the number of full-featured user licenses in your organization

For example, if your organization has three full licenses, you have 3 MB of custom setting storage. If your organization has 20 full licenses, you have 10 MB of storage.

Each Certified managed package gets its own separate limit in addition to your organization limit. For example, if your organization has two certified managed packages installed and your organization has three full licenses, each certified managed package can have 3 MB of custom setting storage, in addition to your organization’s 3 MB custom setting storage limit.

  • 300 fields per custom setting.
  • You can’t share a custom setting object or record.
  • No owner is assigned when a custom setting is created, so the owner can’t be changed.
  • Custom settings are a type of custom object. Each custom setting counts against the total number of custom objects available for your organization.

For more details, please refer below link:

Official Link

Permanent link to this article:

1 comment

    • Saurabh on August 5, 2020 at 2:42 am
    • Reply

    Hi Ankush,

    I have written one below code where I am masking all the email values of all custom settings (field type can be email or text ) with .invalid . Now I need to convert this into Batch Class and I am really facing challenges in writing that . Can you please help me in looking this . Any urgent help will be appreciated. Thanks .

    Map gd = Schema.getGlobalDescribe();

    for ( String objectName : gd.keySet() ) {

    Schema.SObjectType result = gd.get( objectName );

    if ( result.getDescribe().isCustomSetting() ) {

    String query = ‘SELECT ‘;
    List listFields = new List ();
    Map objectFields = result.getDescribe().fields.getMap();
    for ( String s : objectFields.keySet() ) {

    /* Checking whether the Field type is Email or Field Label contains Email */
    if ( String.valueOf( objectFields.get( s ).getDescribe().getType() ) == ‘Email’ ||
    ( String.valueOf( objectFields.get( s ).getDescribe().getLabel() ).contains( ‘Email’ ) &&
    String.valueOf( objectFields.get( s ).getDescribe().getType() ) == ‘String’ ) ) {

    system.debug( ‘Inside’ );
    query += s + ‘,’;
    listFields.add( s );



    if ( listFields.size() > 0 ) {

    query = query.removeEnd( ‘,’ );
    query += ‘ FROM ‘ + objectName;
    List listRecords = Database.query( query );

    if ( listRecords.size() > 0 ) {

    for ( sObject obj : listRecords ) {

    for ( String strField : listFields ) {

    if ( obj.get( strField ) != null )
    obj.put( strField, obj.get( strField ) + ‘.test’ );



    update listRecords;





Leave a Reply

Your email address will not be published.