All posts

Custom Settings vs Custom Labels explained

Salesforce provides Custom Labels and Custom Settings as tools to make your org more dynamic and configurable. While they share some similarities, they…

Salesforce provides Custom Labels and Custom Settings as tools to make your org more dynamic and configurable. While they share some similarities, they serve distinct purposes and are optimized for different types of use cases.

This guide explains what Custom Labels and Custom Settings are, when to use them, and compares their strengths, limitations, and use cases.

What Are Custom Labels?

Custom Labels allow you to store text values that can be translated into multiple languages for multilingual Salesforce orgs. They are primarily used to make static text dynamic, such as error messages, instructions, labels for fields or buttons, and user-facing messages.

Key Features:

  • Multilingual Support: Labels can have translations for different languages.
  • Global Access: Accessible from Apex, Visualforce, Lightning Components, validation rules, formulas, and Flows.
  • Static Text: Optimized for storing plain text values that don’t change frequently.

What Are Custom Settings?

Custom Settings store configuration data that can be accessed programmatically across the org. They are useful for application logic, reference data, and storing user- or profile-specific settings.

Key Features:

  • No Translation Support: Custom Settings don’t support multiple languages.
  • Programmatic Use: Primarily used in Apex, validation rules, and Flows for storing application data.
  • Dynamic Data: Useful for data that might need frequent updates, such as toggles or thresholds.

Comparing Custom Labels and Custom Settings

  • Purpose
    • Custom Labels: Display dynamic, user-facing text.
    • Custom Settings: Store configuration and reference data.
  • Multilingual Support
    • Custom Labels: Yes. Translatable into multiple languages.
    • Custom Settings: No. Static text only.
  • Data Types
    • Custom Labels: Stores text only.
    • Custom Settings: Can store various field types (text, number, checkbox).
  • Access in Apex
    • Custom Labels: Use Label.LabelName to retrieve the value.
    • Custom Settings: Use .getInstance() or .getAll() to retrieve data.
  • Access in Validation Rules / Flows
    • Custom Labels: Yes (via $Label.).
    • Custom Settings: Yes (via $Setup.).
  • Deployment
    • Custom Labels: Included in metadata deployments.
    • Custom Settings: Custom Setting records are not deployable by default.
  • Data Relationships
    • Both: No relationships (flat structure).
  • Caching
    • Custom Labels: Not cached; retrieved dynamically.
    • Custom Settings: Cached for faster access.
  • Storage Limit
    • Custom Labels: 1000 characters per label, unlimited total labels.
    • Custom Settings: 10MB per org across all settings.

When to Use Custom Labels

Custom Labels are best suited for textual values displayed to users, especially in multilingual contexts. Use Custom Labels when:

  1. Multilingual Orgs
    • Store error messages, field labels, or help text that needs to be translated.
    • Example: Display “Record not found” as “Enregistrement introuvable” for French users.
  2. User-Facing Text
    • Use in Lightning Components, Visualforce, or validation rules to ensure consistent messaging.
    • Example: Dynamic button text or help messages like “Click here to submit.”
  3. Static Values
    • Store static values like application names or company-wide messages.
    • Example: “Welcome to Acme Corp CRM!”

Custom Label Example:

  • Label Name: Error_RecordNotFound
  • Value (Default): Record not found.
  • Translation (French): Enregistrement introuvable.

Formula Usage Example:

IF(ISBLANK(Name), $Label.Error_RecordNotFound, "Valid Record")

When to Use Custom Settings

Custom Settings are ideal for storing configuration data or values used in application logic. Use Custom Settings when:

  1. Dynamic Configuration
    • Store toggles, limits, or rules that might change frequently.
    • Example: Enable/disable a feature for specific profiles or users.
  2. Reference Data
    • Store reusable values that drive business logic.
    • Example: Threshold values for lead scoring or discount percentages.
  3. Programmatic Use
    • Use in Apex or Flows for application logic.
    • Example: API keys, endpoint URLs, or feature toggles.
  4. Hierarchical Overrides
    • Use Hierarchy Custom Settings for user- or profile-specific configurations.
    • Example: Set a default region for a specific profile.

Custom Setting Example:

  • Setting Name: ValidationControl__c
  • Fields:
    • EnableValidationRules__c (Checkbox)
    • MaxDiscount__c (Number)

Validation Rule Usage Example:

$Setup.ValidationControl__c.EnableValidationRules__c &&
Discount__c > $Setup.ValidationControl__c.MaxDiscount__c

Key Differences: Practical Use Cases

  • Error Messages
    • Custom Labels: Translatable error or validation messages.
    • Custom Settings: Not suitable (no translation support).
  • Feature Toggles
    • Custom Labels: Not suitable (no dynamic programmatic toggle).
    • Custom Settings: Ideal for enabling/disabling features.
  • Field Labels or Button Text
    • Custom Labels: Perfect for dynamic, user-facing text.
    • Custom Settings: Not suitable for labels or UI elements.
  • API Keys or Integration Settings
    • Custom Labels: Not suitable (not secure or programmatically editable).
    • Custom Settings: Great for storing endpoints or keys (non-secure).
  • Multilingual Applications
    • Custom Labels: Best choice for translatable text.
    • Custom Settings: Not usable (no translation support).
  • Validation Rules
    • Custom Labels: Store translatable messages for errors.
    • Custom Settings: Ideal for dynamic logic like thresholds.

Combining Custom Labels and Custom Settings

Custom Labels and Custom Settings often complement each other:

  1. Error Messaging with Toggles

    • Use Custom Settings to toggle a feature or validation rule and Custom Labels to define user-friendly error messages.

    Example:

    $Setup.ValidationControl__c.EnableValidationRules__c &&
    ISPICKVAL(StageName, 'Closed Won') &&
    ISBLANK(CloseDate)

    Error Message:

    $Label.Error_CloseDateRequired
  2. Dynamic Configurations with Text Support

  • Use Custom Settings to store thresholds and Custom Labels for multilingual instructions.

Example:

  • Store the maximum discount in a Custom Setting and display an error message from a Custom Label.

Best Practices

For Custom Labels:

  • Always provide meaningful names for easy reference (e.g., Error_InvalidEmail).
  • Add translations for all supported languages in your org.
  • Use labels for all user-facing static text to simplify maintenance and ensure consistency.

For Custom Settings:

  • Group related configurations in the same Custom Setting to keep your org organized.
  • Use Hierarchy Custom Settings for user- or profile-specific logic.
  • Avoid storing sensitive data in Custom Settings; use Named Credentials or Protected Custom Metadata instead.

Conclusion

Both Custom Labels and Custom Settings are essential tools in Salesforce, but they serve distinct purposes:

  • Custom Labels: Best for user-facing, static text that requires multilingual support.
  • Custom Settings: Ideal for dynamic, programmatically used configuration data.

Understanding their strengths and limitations will help you choose the right tool for the job, ensuring your Salesforce org is efficient, maintainable, and scalable.