How to Deploy Custom Settings Records in Salesforce

How to Deploy Custom Settings Records in Salesforce

Custom settings in Salesforce are an integral part of the platform that allows developers and administrators to store custom data that can be accessed efficiently without needing SOQL queries. They’re incredibly useful for application configuration, feature toggles, and environment-specific data.

However, one major hurdle Salesforce professionals often face is deploying custom settings records across environments from sandbox to production or between developer orgs. Unlike custom metadata types, custom settings data isn’t deployable using traditional metadata deployment tools like change sets or Salesforce DX by default.

1. What are Custom Settings?

Custom Settings are similar to Custom Objects, but with streamlined access and optimized storage for configuration-type data. They allow you to avoid hardcoding values and provide easier maintainability.

Types of Custom Settings

There are two types:

1. List Custom Settings

2. Hierarchy Custom Settings

    Example Use Cases:

    2. Why Custom Settings Records Are Not Deployable by Default

    Unlike custom metadata types, custom settings data is treated as actual data, not metadata. That means…

    3. How to Deploy Custom Settings Records

    Let’s explore the various ways to move Custom Settings data between orgs.

    Method 1: Use Data Loader/Data Import Wizard

    Step-by-step:

    1. Export Records

    2. Prepare the CSV.

    3. Import Records

      ✅ Pros:

      ❌ Cons:

      Method 2: Use Apex Scripts

      For repeated or automated deployments, Apex scripts can be used to insert or update custom settings.

      List<MyCustomSetting__c> settings = new List<MyCustomSetting__c>{ new MyCustomSetting__c(Name = 'Setting1', API_Key__c = 'ABC123'), new MyCustomSetting__c(Name = 'Setting2', API_Key__c = 'XYZ789') }; insert settings;

      How to deploy:

      ✅ Pros:

      ❌ Cons:

      Method 3: Custom Metadata Alternative

      If your use case involves configuration data that needs to be deployed via Change Sets or Metadata API, consider switching to Custom Metadata Types.

      Pros:

      ❌ Cons:

      Method 4: Use Salesforce DX + SFDX Data Commands

      If you are using Salesforce DX, you can include custom setting data in scratch orgs or use data import commands.

      sfdx force:data:tree:export -q "SELECT Name, Field1__c FROM MyCustomSetting__c" -d ./data -p sfdx force:data:tree:import -f ./data/MyCustomSetting__c.json

      ✅ Pros:

      ❌ Cons:

      Method 5: Use Third-Party Tools

      Tools like Gearset, Copado, Flosum, or AutoRABIT provide GUI-based solutions to move custom settings data.

      ✅ Pros:

      ❌ Cons:

      4. Best Practices for Deploying Custom Settings

      Here are a few things to keep in mind when working with custom settings across environments:

      1. Use Custom Metadata When Possible

      If your data doesn’t need to change per org or user, custom metadata types are a better alternative. They are metadata and can be deployed easily.

      2. Use Naming Conventions

      When inserting records via script or import, ensure names are consistent. Some systems rely on it Name as a unique identifier.

      3. Avoid Hardcoded IDs

      Don’t hardcode record IDs in your logic—always refer to Name or create a Key__c field.

      4. Document Settings

      Keep a README or Confluence page that explains the purpose of each custom setting and how to update it.

      5. Secure Sensitive Data

      Do not store secrets or credentials in plain text. Use Named Credentials or Shield Platform Encryption if needed.

      5. Real-World Scenarios

      ✅ Scenario 1: Feature Flag for a New Functionality

      Use a list custom setting with fields like Feature_Name__c and Is_Enabled__c. Deploy data using Apex script after moving the Custom Setting metadata.

      ✅ Scenario 2: Org-Specific Configurations

      Use Data Loader to export/import org-specific API keys or URLs for integrations, using different values in sandbox and production.

      ✅ Scenario 3: Migrating from Sandbox to Production

      Conclusion:

      Deploying Custom Settings records in Salesforce may seem tricky at first, but with the right approach and tools, you can streamline the process significantly. Whether you prefer a script-based strategy using Apex or a more user-friendly route with tools like Data Loader or Gearset, the key is consistency and planning. Whenever possible, opt for Custom Metadata Types for metadata-bound values, and reserve Custom Settings for data that is environment-specific or frequently changing.

      Contact Us
      Loading
      Your message has been sent. Thank you!
      © Copyright iTechCloud Solution 2024. All Rights Reserved.