welcome to XRM blog

Keep in touch with latest CRM/ERP articles

To remain competitive your organisation must be efficient across the business process spectrum. To do so you need to take sound decisions based on a balance between the cost and risk. To do so you will be heavily dependent on your content management in itself needs...

image
Blog

How to Use Custom Metadata Types for Dynamic Business Logic in Salesforce

By Vikas Sain on 10/6/2025

💬"Imagine updating your org’s logic without changing a single line of code. That’s the power of Custom Metadata Types." 

Salesforce is all about flexibility. But if you're hardcoding values in Apex or creating dozens of formula fields for every business rule, you're missing a game-changing feature: Custom Metadata Types (CMDT). 

In this blog, we’ll break down everything you need to know to start using CMDT to build dynamic, flexible, and admin-friendly business logic—the smart way. 

What is Dynamic Business Logic? 

Dynamic Business Logic means building systems where rules, thresholds, values, or decision paths can be changed without touching code or redeploying. 

Example: 

Changing the discount % by customer type. 

Instead of coding this value, store them as metadata that admins can manage. 

What Are Custom Metadata Types?

Custom Metadata Types (CMDT) are like custom objects but designed to store configuration and logic data — not transactional data. 

Key Features:

1. Fully deployable via change sets or packages 

2. Accessible in Apex, Validation Rules, and Flows 

3. No DML required (read-only, but fast and cacheable) 

4. Managed via Setup (admin-friendly) 

Step-by-Step: Create Custom Metadata for Business Logic 

Use Case: Discount by Customer Tier 

Problem: 
In many Salesforce implementations, discount values based on customer tiers (e.g., Gold, Silver, Bronze) are hardcoded into Apex classes or Flows. This makes it difficult for admins to update discount logic without involving developers, risking delays and potential deployment issues. 

Solution:  
Use Custom Metadata Types (CMDT) to store and manage discount percentages for each customer tier. This allows you to dynamically apply discounts based on the Account's Tier__c field. Admins can easily update discount values directly in the Setup UI—no code changes or deployments required. 

Result:
Business logic becomes configurable, scalable, and admin-friendly,enabling faster updates and better alignment with business needs—all while maintaining clean, reusable code. 

Let’s learn how to set up a Custom Metadata Type in order to solve the problem. 

Step 1: Create the Custom Metadata Type

1. Go to Setup → Search Custom Metadata Types. 

2. Click New Custom Metadata Type. 

3. Label: Customer Tier Discount. 

4. Object Name: Customer_Tier_Discount. 

5. Enable: “Visible to all users”. 

 

Step 2: Add Fields to the CMDT 

Click Manage Records → New Field for each: 

Field Label Field Type  API Name 
Tier Name  Text  Tier_Name__c 
Discount (%)  Number Discount__c

 

 

Similarly, you can add the second field. 

Step 3: Add CMDT Records (Your Logic) 

Click Manage Records → New 

Create:

1. Tier Name: Gold | Discount: 20

2. Tier Name: Silver | Discount: 10

3. Tier Name: Bronze | Discount: 5

 

Similarly, you can add as much as you want. 

Now you can use the Custom Metadata Type created above in apex class to retrieve the discount value. 

 

Best Practices for CMDT

1. Use naming conventions (Rule_Config__mdt, Mapping__mdt). 

2. Keep descriptions updated for each field and record. 

3. Group related rules under one CMDT. 

4. Avoid using CMDT for large transactional data. 

5. Use it to replace IF-ELSE hardcoding in Apex. 

Wrap-Up: Why CMDT Changes the Game 

Custom Metadata Types give you the ability to: 

1. Move business rules out of code. 

2. Empower admins to maintain logic. 

3. Deploy logic across orgs like metadata. 

4. Improve maintainability and performance. 

Next time you’re about to hardcode a value in Apex… stop. Ask yourself: 

“Can I turn this into a Custom Metadata Type instead?” 

#CMDTSalesforce
#CustomMetadatainApex
#DynamicBusinessLogicSalesforce
#No-CodeSalesforceAutomation
#SalesforceAdminTips
#SalesforceApexBestPractices
#SalesforceConfiguration
#SalesforceCustomMetadataTypes
#SalesforceDiscountLogic
Author
Blog Calendar
Blog Calendar List
2025 Nov  5  2
2025 Oct  12  5
2025 Sep  50  7
2025 Aug  32  4
2025 Jul  18  9
2025 Jun  23  6
2025 May  64  9
2025 Apr  35  6
2025 Mar  66  7
2025 Feb  41  6
2024 Nov  12  1
2024 Aug  8  1
2024 Apr  61  4
2024 Mar  176  4
2024 Feb  528  3
2024 Jan  36  7
2023 Dec  45  6
2023 Nov  699  5
2023 Oct  935  12
2023 Sep  2126  9
2023 Aug  655  6
2023 Jul  49  6
2023 Jun  27  4
2023 May  45  5
2023 Apr  92  5
2023 Mar  233  6
2023 Feb  180  5
2023 Jan  96  4
2022 Dec  98  7
2022 Nov  305  2
2022 Sep  14  1
2022 Aug  32  2
2022 Jun  11  2
2022 May  6  2
2022 Apr  12  2
2022 Mar  2  1
2022 Feb  2  1
2022 Jan  1  1
2021 Dec  4  1
2021 Nov  2  1
2021 Oct  2  1
2021 Sep  14  1
2021 Aug  49  5
2021 Jul  53  4
2021 Jun  1931  5
2021 May  43  3
2021 Apr  2284  3
2021 Mar  217  5
2021 Feb  2871  7
2021 Jan  4311  9
2020 Dec  625  7
2020 Sep  85  3
2020 Aug  795  3
2020 Jul  139  1
2020 Jun  104  3
2020 Apr  109  3
2020 Mar  19  2
2020 Feb  34  5
2020 Jan  48  7
2019 Dec  18  4
2019 Nov  42  1
2019 Jan  23  2
2018 Dec  156  4
2018 Nov  68  3
2018 Oct  18  3
2018 Sep  1306  11
2018 Aug  7  2
2018 Jun  21  1
2018 Jan  74  2
2017 Sep  591  5
2017 Aug  17  1
2017 Jul  17  2
2017 Jun  65  2
2017 May  21  1
2017 Apr  40  2
2017 Mar  145  4
2017 Feb  872  4
2016 Dec  213  3
2016 Nov  1116  8
2016 Oct  358  10
2016 Sep  835  6
2016 Aug  40  1
2016 Jun  1900  6
2016 May  118  3
2016 Jan  73  2
2015 Dec  784  6
2015 Nov  4  1
2015 Oct  13  1
2015 Sep  1475  6
2015 Aug  14  1
2015 Jul  129  2
2015 Jun  11  1
2015 May  20  1
2015 Apr  30  3
2015 Mar  80  3
2015 Jan  5350  4
2014 Dec  18  1
2014 Nov  2260  4
2014 Oct  69  1
2014 Sep  107  2
2014 Aug  5345  1
2014 Jul  49  2
2014 Apr  2606  12
2014 Mar  308  17
2014 Feb  223  6
2014 Jan  1510  16
2013 Dec  21  2
2013 Nov  695  2
2013 Oct  256  3
2013 Sep  13  1
2013 Aug  40  3
2013 Jul  214  1
2013 Apr  62  6
2013 Mar  2406  10
2013 Feb  131  3
2013 Jan  353  2
2012 Nov  63  2
2012 Oct  520  10
Tag Cloud
Interested in our services? Still not sure about project details? get a quote