Salesforce: Understanding Custom Metadata, Custom Settings, Custom Labels, Custom Objects & Record Types

Salesforce: Understanding Custom Metadata, Custom Settings, Custom Labels, Custom Objects & Record Types 

Salesforce provides various ways to store and manage data, configurations, and labels. Understanding when to use Custom Metadata, Custom Settings, Custom Labels, and Custom Objects can significantly improve efficiency and maintainability in Salesforce implementations. 

 

  1. Custom Metadata

Purpose: 

Stores metadata/configuration that can be deployed across environments. 

🔹 Usage: 

  • Ideal for storing application configurations, feature flags, or settings that shouldn’t count against data storage. 

🚀 Key Features: 

  • Can be deployed via Change Sets, Metadata API, or packages. 
  • Not counted towards data storage. 
  • Accessed in Apex using SOQL (SELECT queries). 
  • Cannot be modified in Apex (only via Metadata API or manually). 
  • Cached for faster performance. 

💡 Example Use Case: 

  • Feature toggles for enabling/disabling functionalities. 
  • Storing API endpoint URLs or static values used across multiple places. 

 

  1. Custom Settings

Purpose: 

Stores application data/settings that can be accessed without SOQL queries. 

🔹 Types of Custom Settings: 

  1. Hierarchy Custom Settings 
  • Can store user- or profile-specific settings. 
  • Falls back to profile-level, then org-wide defaults if no user-level setting exists. 
  1. List Custom Settings 
  • Acts like a custom object but does not count toward data storage. 
  • Data is static and cannot be modified in Apex. 

🚀 Key Features: 

  • Faster access (does not require SOQL, accessed like $Setup.CustomSettingName__c in Apex). 
  • Cannot be deployed with metadata (values must be manually set in each org). 
  • Best suited for lightweight configurations. 

💡 Example Use Case: 

  • Defining different discount percentages per user profile. 
  • Storing external system credentials or static mappings. 

 

  1. Custom Labels

Purpose: 

Stores text-based values that can be translated into multiple languages. 

🚀 Key Features: 

  • Used for storing messages, labels, or UI text to support multilingual translations. 
  • Can be used in Apex (System.Label.Label_Name), Visualforce, Lightning Components, and formulas. 
  • Cannot be updated dynamically in Apex. 

💡 Example Use Case: 

  • Storing error messages or button labels (“Save” button → “Guardar” in Spanish). 
  • Storing API keys that should not be hardcoded in code. 

 

  1. Custom Objects

Purpose: 

Stores actual business data, similar to standard objects like Account and Contact. 

🚀 Key Features: 

  • Stores records (counts against data storage). 
  • Can have relationships (Lookup/Master-Detail). 
  • Supports Triggers, Workflows, Flows, and Validation Rules. 
  • Can be queried using SOQL & SOSL. 
  • Can be exported/imported using Data Loader. 

💡 Example Use Case: 

  • Creating an object “Employee” to store employee records. 
  • Creating an object “Project” to track different projects in an organization. 

 

📌 Differences Between Custom Metadata, Custom Settings, Custom Labels & Custom Objects 

Feature  Custom Metadata  Custom Settings  Custom Labels  Custom Objects 
Purpose  Configuration  Application Data  UI Messages  Business Data 
Stored in  Metadata  Application Cache  Translation Table  Database 
Deployment  Yes  No  Yes  Yes 
SOQL Queries  Yes  No  No  Yes 
Access in Apex  SOQL  $Setup  System.Label  SOQL/SOSL 
Modifiable in Apex?  No  No  No  Yes 
Use Case  Feature Flags  Profile/User-Specific Config  Multi-language Support  Business Data 

🛠 When to Use What? 

  • Custom Metadata → If you need configurable settings that can be deployed across orgs. 
  • Custom Settings → If you need settings that are fast to access but do not need to be deployed. 
  • Custom Labels → If you need multilingual support for UI messages. 
  • Custom Objects → If you need to store actual business data. 

 

📌 What is a Record Type in Salesforce? 

A Record Type in Salesforce allows you to define different business processes, page layouts, and picklist values for different users based on their profiles. 

🚀 Features of Record Types: 

Different Page Layouts → Show different fields based on the record type. Different Picklist Values → Customize dropdown values for different record types. Profiles-Based Access → Restrict access to record types based on user profiles. Different Business Processes → Support different workflows for different record types. 

💡 Example Scenarios Where Record Types Are Useful: 

  1. Sales Process Customization 
  • Example: Different sales processes for B2B (Business-to-Business) and B2C (Business-to-Consumer) accounts. 
  1. Case Management 
  • Example: Support cases categorized as Technical Issues and Billing Issues with different fields. 
  1. Job Applications 
  • Example: A Job Application object with different record types for Full-Time Jobs and Internships. 

 

📝 Using Record Types in Apex 

1️ Retrieve Record Type ID 

Id recordTypeId = [SELECT Id FROM RecordType WHERE Name = ‘B2B Account’ AND SObjectType = ‘Account’ LIMIT 1].Id; 

2️ Assign a Record Type While Creating a New Record 

Account acc = new Account(); 

acc.Name = ‘Tech Corp’; 

acc.RecordTypeId = recordTypeId; 

insert acc; 

3️ Check Record Type in Apex 

if (acc.RecordTypeId == recordTypeId) { 

    System.debug(‘This is a B2B Account.’); 

} 

4️ Use Record Type in Trigger 

trigger AccountTrigger on Account (before insert, before update) { 

    for (Account acc : Trigger.new) { 

        if (acc.RecordTypeId == ‘0123456789ABCDEFG’) { 

            acc.Industry = ‘Technology’; 

        } 

    } 

} 

 

⚠️ Limitations of Record Types 

🚧 Users can have only one default record type per object. 🚧 Changing a record’s record type does not automatically update existing picklist values. 🚧 Cannot apply Record Types on Standard Objects like “Task” or “Events”. 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *