Loading
Enhance Salesforce with Code
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Custom Metadata Types and Validation Rule Formulas

          Custom Metadata Types and Validation Rule Formulas

          Use custom metadata records to store validation rule record values. Then, reference the records directly within validation rules and eliminate the need to add the same values into different validation rules. Using packaging? You can define the logic and leave customization to a subscriber.

          Required Editions

          Available in: Salesforce Classic and Lightning Experience

          Available in: Enterprise, Performance, Unlimited, and Developer Editions

          You can create, edit, and delete custom metadata type records from installed packages in: Group and Professional Editions

          Example
          Example Consider a validation rule that limits the discount on a brand to 10 percent. When you apply a change in the discount, values within the validation rule need updating. With multiple rules that check the discount amount, you must update all rules. By using custom metadata records within these validation rules, you simply update the discount amount within the custom metadata record without modifying any of the validation rules.
          • Create a custom metadata type. In this example, the custom metadata type is named DiscountLimits.
          • Create a custom field for your type named maxDiscount.
          • Create a record and name it FoodDiscount.

          When done, you can reference the custom metadata record in your validation rule. The syntax is:

          $CustomMetadata.CustomMetadataTypeAPIName.RecordAPIName.FieldAPIName

          Use the correct suffixes. For the custom metadata type, use __mdt. For fields, use __c. Records require no suffix. Your validation rule for this example looks like this:

          Discount > $CustomMetadata.DiscountLimits__mdt.FoodDiscount.maxDiscount__c

          You can also use the insert field dialog to reference custom metadata records within a validation rule. In Setup, go to management settings for the relevant object.

           
          Loading
          Salesforce Help | Article