Understanding the Role of Custom Settings in Salesforce

Salesforce is a platform that thrives on flexibility, and at the heart of its configurable nature lies a powerful feature known as Custom Settings. These are not just minor tools tucked away in the back end; they are crucial in ensuring seamless performance, easy configuration, and efficient data retrieval. Often compared with custom objects, Custom Settings are designed to hold static configuration data that can be accessed without the overhead of standard query methods. This makes them especially useful in scenarios where speed, reliability, and simplicity are paramount.

Unlike standard custom objects which are stored in the database and accessed using SOQL, Custom Settings reside in application cache memory. This architectural nuance makes them faster to access and more suitable for use cases where the same data must be repeatedly accessed by multiple components, processes, or users.

What Makes Custom Settings Different?

While they share a visual and structural resemblance to custom objects, Custom Settings differ significantly in purpose and behavior. Custom objects are designed to hold transactional or business data and are used widely in workflows, reports, and data analysis. On the other hand, Custom Settings are optimized for system-wide configurations that don't change frequently and need to be referenced often.

For example, if your application needs to reference a set of country dialing codes every time a new customer record is created, using Custom Settings avoids repeated SOQL queries and accelerates the operation by fetching the data from the cache instead of the database.

Another distinguishing feature is their accessibility across different components of Salesforce, such as Apex classes, formula fields, validation rules, and workflow rules. This cross-platform utility makes them invaluable in creating scalable and modular applications.

Advantages of Using Custom Settings

There are several compelling reasons to use Custom Settings in your Salesforce org. These include:

  • Performance Efficiency: Because the data is stored in cache, accessing it does not consume any SOQL governor limits. This can dramatically improve performance, especially in large-scale applications.

  • Configurability Without Code Changes: Administrators can update values in Custom Settings directly from the UI, eliminating the need for code changes and deployments.

  • Centralized Data Management: Configuration values used across multiple modules can be managed from a single location, reducing redundancy and potential errors.

  • Security and Control: Custom Settings respect organizational security controls, and specific values can be exposed or restricted depending on user roles and access levels.

The Two Primary Types of Custom Settings

Salesforce offers two main types of Custom Settings, each serving a unique set of use cases.

List Custom Settings

These are designed to hold a static list of values accessible by all users in an organization. The data in List Custom Settings is not user-specific and is generally used for storing reference data such as tax rates, status values, API endpoint information, or supported languages.

Each record in a List Custom Setting behaves similarly to a record in a custom object. You can create custom fields, assign values, and use them throughout your Salesforce implementation. What sets List Custom Settings apart is that they are not query-dependent and offer rapid access across your org.

Imagine a scenario where your team needs to frequently reference country calling codes while creating customer records. Rather than querying a database or an external system every time, you can store this data in a List Custom Setting and fetch it directly from memory.

Hierarchy Custom Settings

These are more dynamic and allow for user- or profile-specific configurations. They operate on a hierarchy that enables you to define default values at the organization level while also offering the flexibility to override those values for specific profiles or individual users.

For example, in a retail application, you may want to provide a default discount rate of 10 percent to all customers but offer 20 percent to premium users and 25 percent to specific accounts. Hierarchy Custom Settings allow this kind of customization without requiring complex logic or code.

This feature is especially useful in organizations with varying business rules based on user roles, departments, or locations.

Creating and Configuring List Custom Settings

Creating a List Custom Setting is a straightforward process but involves several key steps:

  1. Navigate to the Setup menu in Salesforce and search for “Custom Settings” in the Quick Find box.

  2. Click on the “New” button to create a new Custom Setting.

  3. Enter the Label and Object Name for your Custom Setting.

  4. Choose “List” as the Setting Type.

  5. Save your settings to proceed to the next screen where you can define custom fields.

  6. Add new fields to your Custom Setting by specifying the field type (e.g., text, number, checkbox) and field label.

  7. Once the fields are added, you can start populating your Custom Setting with records.

An example might be a Custom Setting called “CountryCodes” with fields for “Country Name” and “Dial Code.” You can add records like India with +91, USA with +1, and so on. These values can then be accessed globally across your Salesforce environment without additional query costs.

Configuring Hierarchy Custom Settings

Setting up Hierarchy Custom Settings follows a similar process but includes additional options for specifying user and profile-specific data.

  1. Go to Setup and search for “Custom Settings.”

  2. Click “New” and define the Label and Object Name.

  3. Select “Hierarchy” as the Setting Type.

  4. Save the Custom Setting and proceed to create custom fields.

  5. Define fields such as “Discount Rate” or “Access Level” depending on your requirement.

  6. Once fields are created, click on “Manage” to add records.

  7. You can now set default values for the entire organization and override them for specific users or profiles.

For instance, create a record for the default organization-level discount rate (say 10 percent), then create another for a specific profile like Premium Customers (20 percent), and perhaps a third one for a VIP user with a 25 percent rate.

These values will be fetched automatically in your application, with Salesforce choosing the most specific one based on the user’s profile or ID.

Practical Scenarios Where Custom Settings Shine

There are countless real-world examples where Custom Settings can simplify architecture and improve performance:

  • Regional Tax Calculations: Store varying tax percentages for different regions and reference them in formula fields or Apex triggers.

  • Feature Toggles: Use checkboxes to enable or disable features across different environments or user roles.

  • Integration Parameters: Store API credentials, endpoints, and timeout values, especially useful for environments where these might differ.

  • Data Thresholds: Store limits such as maximum transaction values, usage caps, or alert thresholds.

  • Language Translations: Maintain a dictionary of commonly used phrases or field labels in multiple languages.

Considerations and Limitations

Despite their advantages, Custom Settings come with a few caveats:

  • Limited to 300 Fields: A single Custom Setting cannot have more than 300 fields.

  • Deployment Limitations: The data in Custom Settings does not move with change sets. It must be manually replicated in each environment.

  • No UI Tabs: Custom Settings do not have a native UI tab like standard objects do, limiting their accessibility for non-technical users.

  • Counts Toward Custom Object Limit: They count against the overall limit of custom objects in your org.

In cases where deployment and advanced UI support are required, Custom Metadata Types may be a better fit. They are similar in structure but more suitable for managed packages and environments requiring frequent migrations.

Best Practices for Using Custom Settings

To make the most out of Custom Settings, follow these best practices:

  • Use List Custom Settings for data that is static and consistent across users.

  • Leverage Hierarchy Custom Settings when personalization based on user or profile is needed.

  • Keep the number of fields manageable to avoid hitting platform limits.

  • Document your Custom Settings thoroughly to ensure they are understood by all team members.

  • Regularly review and update values to ensure they remain relevant.

It’s also advisable to abstract access to Custom Settings in Apex through utility classes. This promotes better maintainability and reduces the risk of introducing errors if field names or settings change.

Summary of Key Concepts

Custom Settings in Salesforce offer a powerful way to store and retrieve configuration data efficiently. They are particularly valuable in large-scale applications where speed and modularity are critical. By understanding the two types—List and Hierarchy—and applying them appropriately, organizations can reduce complexity, enhance performance, and make their Salesforce implementations more adaptable.

While not suitable for every scenario, Custom Settings serve as an ideal solution for system-wide constants, user-specific settings, and cached data that need to be accessed frequently. For use cases requiring more advanced features like deployment readiness and validation rules integration, Custom Metadata Types may be considered as an extension or replacement.

Mastering Custom Settings opens the door to more efficient and robust Salesforce applications. By centralizing configuration data and decoupling it from business logic, teams can achieve greater agility and fewer errors. Understanding when and how to use List versus Hierarchy Custom Settings lays the foundation for cleaner, more maintainable architecture.

Creating List and Hierarchy Custom Settings in Salesforce

Understanding the theory behind Custom Settings is only the beginning. Knowing how to implement them effectively in a real-world Salesforce org is what translates conceptual understanding into practical results. This section focuses on the exact steps required to create both List and Hierarchy Custom Settings, including examples to help solidify the process.

Navigating to Custom Settings

Before creating any settings, one must navigate to the Custom Settings interface within Salesforce:

  1. Go to Setup in your Salesforce instance.

  2. Use the Quick Find search box and type in "Custom Settings."

  3. Click on the "Custom Settings" link under the "Develop" section.

You will now see a list of existing Custom Settings or a prompt to create a new one.

Creating a List Custom Setting

To illustrate the steps, consider an example where your organization wants to store international phone codes to auto-fill them during lead creation.

Step-by-Step Instructions:

  1. Click "New" to create a new Custom Setting.

  2. Enter the Label: For instance, "Country Phone Codes."

  3. Enter the Object Name: Use something like "CountryPhoneCodes."

  4. Select Setting Type: Choose "List."

  5. Visibility: Choose Public to allow access from all Apex classes and triggers.

  6. Click Save.

Once saved, the system redirects to the Custom Setting's detail page.

Adding Fields to the List Custom Setting:

  1. Click "New" under the section for Custom Fields.

  2. Choose the field type, such as Text, Number, or Checkbox.

  3. For our example, choose Text and label it as "DialingCode."

  4. Set the length to 5, assuming that international codes won't exceed that.

  5. Click Next, then Save.

Repeat this process to add other necessary fields, such as "CountryName."

Adding Records to the Setting:

  1. Return to the Custom Setting’s main page.

  2. Click "Manage."

  3. Click "New" to create a new record.

  4. Fill in "CountryName" as "India" and "DialingCode" as "+91."

  5. Click Save.

Repeat the above for countries like the United States, Canada, Australia, etc.

These records are now available across your org without using a single SOQL query. Accessing them in Apex or referencing them in workflows is seamless and efficient.

Creating a Hierarchy Custom Setting

Next, let’s walk through creating a Hierarchy Custom Setting, which offers the added benefit of assigning different values at the organization, profile, and user level.

Assume you are creating a discount configuration module for a retail organization.

Step-by-Step Instructions:

  1. In Setup, return to the "Custom Settings" section.

  2. Click "New."

  3. Enter the Label: For instance, "Discount Configuration."

  4. Object Name: Use something like "DiscountConfig."

  5. Choose "Hierarchy" as the Setting Type.

  6. Set the visibility to Public.

  7. Click Save.

Adding Fields to Hierarchy Custom Setting:

  1. Click "New" to add a custom field.

  2. Select "Percent" as the data type.

  3. Field Label: "DiscountRate."

  4. Precision: 2 (to allow for decimal values like 10.25%).

  5. Click Next, then Save.

Configuring Default Values:

  1. On the main setting page, click "Manage."

  2. Click "New."

  3. Location: Choose "Organization."

  4. Set "DiscountRate" to 10.

  5. Click Save.

Overriding for Specific Profiles:

  1. Click "New" again.

  2. Location: Choose "Profile."

  3. Select a Profile, e.g., PremiumUser.

  4. Set "DiscountRate" to 20.

  5. Save.

Overriding for Specific Users:

  1. Click "New."

  2. Location: Choose "User."

  3. Select a specific user.

  4. Set "DiscountRate" to 25.

  5. Save.

These steps demonstrate the versatility of Hierarchy Custom Settings. Depending on who logs in, the application can dynamically determine which discount rate to apply based on the most specific available setting.

Accessing Custom Settings in Apex

One of the biggest advantages of Custom Settings is that they can be accessed without SOQL, making your Apex code cleaner and more efficient.

Accessing List Custom Settings:

List<CountryPhoneCodes__c> codes = CountryPhoneCodes__c.getAll().values();

This retrieves all stored country phone codes.

Accessing Hierarchy Custom Settings:

DiscountConfig__c discount = DiscountConfig__c.getInstance(UserInfo.getUserId()); Decimal rate = discount.DiscountRate__c;

This retrieves the most specific discount rate for the current user, considering the hierarchy.

Use Cases in Business Processes

Let’s explore several practical implementations of Custom Settings in various departments:

Marketing

Store campaign thresholds, default opt-in values, and time zone preferences for international campaigns.

Sales

Use Hierarchy Settings to assign default quotas, lead conversion thresholds, or regional currency preferences.

Support

List Custom Settings can be used to manage escalation matrices, response time targets, or predefined case categories.

Integration

Store API credentials, endpoint URLs, and timeout values. These are typically the same across users and are ideal for List Custom Settings.

Salesforce Custom Settings simplify configuration and improve performance by caching important data and making it accessible without the need for complex queries. Both List and Hierarchy types have unique advantages and choosing the correct one depends on the use case.

Creating and managing these settings is straightforward but offers powerful results. With this foundational knowledge, developers and administrators can create more flexible and scalable applications.

The next section of this guide will examine how Custom Settings compare with Custom Metadata Types, along with guidelines on choosing the best data management method for specific business needs.

Comparing Custom Settings with Custom Metadata Types

As Salesforce has evolved, new tools have been introduced to handle configuration data more robustly. One such enhancement is Custom Metadata Types. While Custom Settings remain a powerful feature, Custom Metadata has emerged as a more advanced alternative in many scenarios. Understanding the similarities and differences between the two will enable developers and architects to make informed decisions.

Core Similarities

Both Custom Settings and Custom Metadata Types are designed to store application configuration data. They:

  • Support custom fields.

  • Allow easy reference in Apex, formulas, validation rules, and processes.

  • Provide a mechanism for data reuse and centralization.

Key Differences

The primary distinction lies in deployment and manageability.

  • Deployment: Custom Settings data is not deployable via change sets or metadata API. Custom Metadata Types, on the other hand, allow records to be packaged and deployed across environments.

  • Test Classes: Custom Metadata records are visible in test classes without special handling, while Custom Settings require SeeAllData=true or mock data creation.

  • UI and Record Visibility: Custom Metadata Types have a dedicated object-like UI and can be created using setup wizards. Custom Settings have a simpler, less integrated interface.

  • Access Control: Custom Metadata Types are protected from user edits unless specifically made visible. Custom Settings can be modified by any user with the proper permissions.

When to Use Each Option

Use Custom Settings When:

  • Data should be accessible from the application cache.

  • Configuration changes are made frequently by admins.

  • User- or profile-specific configuration is required (Hierarchy Settings).

Use Custom Metadata Types When:

  • Configuration needs to be deployed between orgs.

  • Records must be referenced in test classes without inserting data.

  • There is a need to store data with stricter visibility and governance.

Migrating from Custom Settings to Custom Metadata

Organizations with legacy implementations often look to move from Custom Settings to Custom Metadata Types for the advantages outlined above. The migration process involves:

  1. Identifying the existing Custom Setting.

  2. Creating a corresponding Custom Metadata Type.

  3. Defining the same custom fields.

  4. Exporting data from Custom Settings.

  5. Creating metadata records manually or via metadata deployment tools.

  6. Updating Apex classes, triggers, and references.

This transition improves maintainability and enables smoother CI/CD workflows.

Performance Considerations

Both Custom Settings and Custom Metadata Types offer high performance due to their low-overhead design. However, Custom Settings slightly edge out Custom Metadata in terms of runtime speed because they leverage in-memory caching more directly.

In highly transactional systems, where even minor delays can impact user experience, the choice may tilt toward Custom Settings. But this gain must be weighed against the long-term benefits of maintainability and scalability that Custom Metadata Types offer.

Security and Compliance

Security is another critical factor. Custom Metadata Types provide better control over record visibility, supporting enterprise governance. Custom Settings are accessible by users with read/write permissions and can be changed unintentionally.

For industries with strict compliance standards, such as finance or healthcare, Custom Metadata Types offer the governance features necessary for audits and regulatory requirements.

Limitations and Workarounds

Custom Settings Limitations:

  • Cannot be included in packages or change sets.

  • Count toward custom object limits.

  • Require manual recreation in different environments.

  • Test classes cannot access them without test data injection.

Workarounds:

  • Use data loader tools to migrate Custom Settings.

  • Abstract settings access in utility classes.

  • Validate usage through custom permission sets or profile configurations.

Real-World Examples of Configuration Approaches

Scenario 1: Global Feature Toggle

A company wants to enable or disable a feature for all users.

  • Custom Setting: Create a List Custom Setting with a checkbox field.

  • Custom Metadata: Create a record with a boolean field to toggle the feature.

If deployment is required across sandboxes and production, the Custom Metadata approach will be more suitable.

Scenario 2: Regional Discounts

Different regions have different discount rates, and these need to be overridden per user role.

  • Custom Setting: Use a Hierarchy Custom Setting with discount percentages.

  • Custom Metadata: Less ideal because it doesn’t support profile/user-specific values.

In this case, Custom Settings are a better fit.

Scenario 3: Integration API Parameters

Store API URLs and keys that vary between dev, UAT, and production.

  • Custom Setting: Accessible but needs to be recreated in each org.

  • Custom Metadata: Can be packaged and deployed.

Custom Metadata Types shine in this context.

Best Practices and Governance

  1. Use Custom Settings for local org-level configuration that doesn’t require deployment.

  2. Use Custom Metadata for packaged configurations or CI/CD workflows.

  3. Document all Custom Settings and Metadata records in internal wikis.

  4. Audit usage annually to remove deprecated or redundant settings.

  5. Encapsulate all accesses in Apex using utility methods for flexibility.

Conclusion

Salesforce provides multiple tools for configuration data, each suited to different needs. Custom Settings remain invaluable for fast access and user-specific configurations. Custom Metadata Types add robust deployment and governance capabilities essential for modern development workflows.

The key lies in understanding the context of your application. Choosing the right configuration mechanism allows your Salesforce org to remain scalable, efficient, and maintainable for years to come.

Back to blog

Other Blogs