8

I have a custom metadata type and a field in it with a value. I am creating a formula field on an object(TestObject) where I would like to reference a value from the above custom metadata type into this formula. I know that in hierarchichal custom settings we can do this by $Setup.CustomSettingName__c.CustomFieldName__c

Could we do similar to that using Custom MetaData Type? Can we reference Custom MetaData type at all?

Thanks for the help!

4 Answers 4

11

Unfortunately, you can't reference custom metadata types in formulas at all. Their primary purpose is to provide metadata that's easy to package and transport between orgs, and primarily intended for use in Apex Code.


You can now reference custom metadata types in validation rules. To do so, specify the object name, record name, and field value:

$CustomMetadata.MyCustomSetting__mdt.DeveloperName.SomeFieldValue__c
5
  • Thanks for the info. I thought we can use it :( So the major difference between custom settings and custom metadata type is that we can deploy records for metadata type which we cannot do with custom setting. Oct 27, 2016 at 16:10
  • 1
    Hey! Might want to update this answer, since now it is possible to reference CMDT in formulas. help.salesforce.com/… Sep 17, 2018 at 19:45
  • @RenatoOliveira thanks for the note. It's really hard to keep track of all my answers for outdated info. I always appreciate help from others.
    – sfdcfox
    Sep 17, 2018 at 19:55
  • And as of Winter 19, not just validation rules but also formula fields.
    – Charles T
    Sep 17, 2018 at 20:32
  • FYI, if you try to reference the formula in a workflow field update it won't work.
    – NSjonas
    Jan 10, 2020 at 5:30
7

We are adding support for custom metadata type in formulas. In Spring '18 you will be able to reference CMT records in validation rules (pilot) with the future addition of formula fields, default values, etc.

https://releasenotes.docs.salesforce.com/en-us/spring18/release-notes/rn_forcecom_development_custom_metadata.htm

Thanks!

7

You can reference CMT records in formula fields starting with the Winter '19 release.

It follows the same syntax as in validation rules:

$CustomMetadata.MyCustomSetting__mdt.DeveloperName.SomeFieldValue__c

Reference: http://releasenotes.docs.salesforce.com/en-us/winter19/release-notes/rn_forcecom_development_custom_metadata_types_ff.htm

3

Good news. Salesforce team is working on adding support for Custom Metadata Types in formulas. It has been confirmed in the success forum:

https://success.salesforce.com/ideaView?id=0873A000000E32UQAS

1
  • That is good news. Custom Metadata could replace certain types of Custom Label usage that are less than ideal without the limitations of Custom Settings.
    – sfdcfox
    May 15, 2017 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.