{"id":12362,"date":"2026-02-17T06:25:49","date_gmt":"2026-02-17T06:25:49","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=12362"},"modified":"2026-02-12T09:25:03","modified_gmt":"2026-02-12T09:25:03","slug":"configurable-apex-in-salesforce-using-custom-metadata-types","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2026\/02\/17\/configurable-apex-in-salesforce-using-custom-metadata-types\/","title":{"rendered":"Configurable Apex in Salesforce Using Custom Metadata Types"},"content":{"rendered":"\n<p>In Salesforce development, hardcoding configuration values such as approval limits or thresholds can quickly become unmanageable. Any change often requires modifying Apex code and redeploying it, which increases risk, slows down operations, and creates unnecessary dependency on developers.<\/p>\n\n\n\n<p><strong>Build Flexible, Admin-Friendly Configuration Without Hardcoding<\/strong><\/p>\n\n\n\n<p>Custom Metadata Types (CMDTs) solve this problem by allowing configuration to be stored as metadata instead of code. This makes configuration declarative, enabling admins to update values without touching Apex. CMDTs are also deployable, meaning configuration can move easily between orgs using change sets or managed packages. Since records are read-only during transactions, they are inherently safe and prevent accidental runtime changes. Additionally, CMDT queries are efficient and can be cached in Apex, reducing the risk of hitting governor limits.<\/p>\n\n\n\n<p>Custom Metadata Types are ideal whenever configuration needs to be centralized, deployable, secure, and easy to maintain.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Business Scenario: Department-Specific Validation Thresholds<\/mark><\/strong><\/h2>\n\n\n\n<p>Consider a company with multiple departments, each having different expense approval thresholds.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Finance<\/strong>: Maximum approval limit of $50,000<\/li>\n\n\n\n<li><strong>HR<\/strong>: Maximum approval limit of $10,000<\/li>\n\n\n\n<li><strong>Sales<\/strong>: Maximum approval limit of $5,000<\/li>\n<\/ul>\n\n\n\n<p>Admins need the flexibility to update these limits quickly without changing or redeploying Apex code. Using custom objects for this purpose would be risky, as frequent queries could impact governor limits, accidental data changes could break approval logic, and deployment would be more complex.<\/p>\n\n\n\n<p>With a Custom Metadata Type named <strong>Approval_Threshold__mdt<\/strong>, admins can create and manage records for each department in a controlled and declarative way.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Creating the Custom Metadata Type<\/mark><\/strong><\/h2>\n\n\n\n<p>To implement this solution, start by creating a Custom Metadata Type in Salesforce.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Navigate to <strong>Setup \u2192 Custom Metadata Types<\/strong> and create a new Custom Metadata Type.<\/li>\n<\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/1.Custom-Meta-DataType.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/1.Custom-Meta-DataType.png\" alt=\"Custom Metadata Types\"><\/a><\/center><font size=\"2\"><center><i>Custom Metadata Types<\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set the label as <strong>Approval Threshold<\/strong> and the object name as <strong>Approval_Threshold__mdt<\/strong>.<\/li>\n<\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/2.Create-new-CMDTs.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/2.Create-new-CMDTs.png\" alt=\"Create New Custom Metadata Types\"><\/a><\/center><font size=\"2\"><center><i>Create New Custom Metadata Types<\/i><\/center><\/font>\n\n\n\n<p>After saving, create the required custom fields:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Department__c<\/strong> as a Picklist<\/li>\n\n\n\n<li><strong>MaxAmount__c<\/strong> as a Currency field<\/li>\n<\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/3.Custom-fields.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/3.Custom-fields.png\" alt=\"Custom Fields\"><\/a><\/center><font size=\"2\"><center><i>Custom Fields<\/i><\/center><\/font>\n\n\n\n<p>Once the fields are created, use <strong>Manage Records<\/strong> to add individual records for Finance, HR, and Sales with their respective threshold values.<\/p>\n\n\n\n<p><strong>Using CMDTs in Apex<\/strong><\/p>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/4.QueryCMDTS.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2026\/02\/4.QueryCMDTS.png\" alt=\"CMDTS in Apex\"><\/a><\/center><font size=\"2\"><center><i>CMDTS in Apex<\/i><\/center><\/font>\n\n\n\n<p>When using CMDTs in Apex, the logic simply reads the configured values and enforces the business rules. Admins can update thresholds declaratively, and the Apex logic automatically adapts without requiring redeployment.<\/p>\n\n\n\n<p>Because CMDT records are cached efficiently, this approach avoids governor limit issues and provides a clean separation between configuration and logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">Conclusion<\/mark><\/strong><\/h2>\n\n\n\n<p>Even in a simple scenario like department-specific validation thresholds, Custom Metadata Types provide a flexible, maintainable, and scalable solution. They eliminate the risks associated with hardcoded values, reduce deployment overhead, and empower admins to manage business rules independently.<\/p>\n\n\n\n<p>By leveraging CMDTs, Salesforce developers can build configurable, enterprise-ready applications that adapt quickly as business requirements evolve.<\/p>\n\n\n\n<p>By following the above blog instructions, you will be able to learn <strong>\u201cConfigurable Apex in Salesforce Using Custom Metadata Types\u201c<\/strong>. If you still have queries or any related problems, don\u2019t hesitate to contact us at <a href=\"mailto:salesforce@greytrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">salesforce@greytrix.com<\/a>. More details about our integration product are available on <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/\" target=\"_blank\" rel=\"noreferrer noopener\">our website<\/a> and <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noreferrer noopener\">Salesforce AppExchange<\/a>.<\/p>\n\n\n\n<p>We hope you may find this blog resourceful and helpful. However, if you still have concerns and need more help, please contact us at <a href=\"mailto:salesforce@greytrix.com\" target=\"_blank\" rel=\"noreferrer noopener\">salesforce@greytrix.com<\/a>.<\/p>\n\n\n\n<p style=\"text-align: justify\"><b>About Us<\/b><\/br>\n<p><a href=\"https:\/\/www.greytrix.com\/\">Greytrix<\/a> \u2013 a globally recognized and one of the oldest Sage Development Partner and a Salesforce Product development partner offers a wide variety of integration products and services to the end users as well as to the Partners and Sage PSG across the globe. We offer Consultation, Configuration, Training and support services in out-of-the-box functionality as well as customizations to incorporate custom business rules and functionalities that require apex code incorporation into the Salesforce platform.<br><br> Greytrix has some unique solutions for Cloud CRM such as <a href=\"\">Salesforce Sage integration<\/a> for <a href=\"https:\/\/www.greytrix.com\/sage-x3-erp\/integration\/\">Sage X3<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-100-integration\/\">Sage 100<\/a> and <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/sage-300-integration\/\">Sage 300 (Sage Accpac)<\/a>. We also offer best-in-class Cloud CRM <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Salesforce customization and development services<\/a> along with services such as Salesforce <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/data-migration-support\/\">Data Migration<\/a>, <a href=\"https:\/\/www.greytrix.com\/salesforce-cloud-services\/crm-development\/\">Integrated App development<\/a>, Custom App development and Technical Support business partners and end users. Salesforce Cloud CRM integration offered by Greytrix works with Lightning web components and supports standard opportunity workflow. Greytrix GUMU&#x2122; integration for Sage ERP \u2013 Salesforce is a 5-star rated app listed on <a href=\"https:\/\/appexchange.salesforce.com\/appxListingDetail?listingId=a0N30000000psM5EAI\" target=\"_blank\" rel=\"noopener\">Salesforce AppExchange<\/a>.<br> The GUMU&#x2122; Cloud framework by Greytrix forms the backbone of cloud integrations that are managed in real-time for processing and execution of application programs at the click of a button.<br><br> For more information on our Salesforce products and services, contact us at <a href=\"mailto:salesforce@greytrix.com\">salesforce@greytrix.com<\/a>. We will be glad to assist you.<\/p>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/12\/30\/custom-settings-in-salesforce\/\" target=\"_blank\" rel=\"noreferrer noopener\">Custom Settings in Salesforce<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2015\/12\/30\/deploying-metadata-using-salesforce-package-part-i-creating-package\/\" target=\"_blank\" rel=\"noreferrer noopener\">Deploying Metadata using Salesforce Package Part I \u2013 Creating Package<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In Salesforce development, hardcoding configuration values such as approval limits or thresholds can quickly become unmanageable. Any change often requires modifying Apex code and redeploying it, which increases risk, slows down operations, and creates unnecessary dependency on developers. Build Flexible, Admin-Friendly Configuration Without Hardcoding Custom Metadata Types (CMDTs) solve this problem by allowing configuration to\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2026\/02\/17\/configurable-apex-in-salesforce-using-custom-metadata-types\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[2803,13,2806,2800,2802,2801,2799,2807,2805,2804,367,2212,2645],"class_list":["post-12362","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-adminfriendly","tag-apex","tag-apexbestpractices","tag-cmdt","tag-configurableapex","tag-custommetadatatypes","tag-declarativeconfiguration","tag-dynamicconfiguration","tag-enterpriseapps","tag-nohardcoding","tag-salesforce","tag-salesforcedevelopment","tag-salesforcetips"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/12362","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=12362"}],"version-history":[{"count":6,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/12362\/revisions"}],"predecessor-version":[{"id":12372,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/12362\/revisions\/12372"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=12362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=12362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=12362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}