61

I’m the original inventor of and lead developer for custom metadata types. Although we have a variety of use cases in mind, custom metadata types are primarily intended to let you develop peers of Salesforce standard metadata types, such as custom fields, tabs, or workflow rules (obviously in this first release we don’t have the power required to duplicate ...


59

This is the list I've compiled. Feel free to add any I've missed. __c Custom Object or Custom field __r Custom relationship field as used in a SOQL query to traverse the relationship __ka KnowledgeArticle __kav KnowledgeArticleVersion __Feed Article Type Feed or Custom Object Feed __ViewStat KnowledgeArticleViewStat __VoteStat KnowledgeArticleVoteStat ...


22

It is not possible to insert test custom metadata, unless you use the Metadata API which would also present a challenge in a test scenario. That said, you should not need to. Custom Metadata is Metadata and as such is not affected by the SeeAllData annotation. See this article dedicated to testing custom metadata.


20

I came up with the below advantages (and disadvantage). I'd be interested if you see any other ones. Perhaps the biggest advantage Custom Metadata Types have over Custom Settings is that the data themselves are considered to be Metadata. So, essentially, you have Metadata about Metadata. Technically, they are called “Components”, and the reason this is ...


14

New in Winter 19! Instantiate Custom Metadata Types in Apex Example from the release notes... How: In this example, the first method is instantiating a custom metadata record, but no records are inserted into memory. The second method retrieves a record, changes it, and returns it to the caller, but the change is not updated in the database. public ...


13

There is possible hack to have different values in tests than it is in organization. This is a good way to have your tests always stable and 100% covered even if custom metadata is changed or removed on your organization. For this hack you just need to put query for custom metadata into separate property which should be settable for unit tests. @...


13

You can track this bug at https://success.salesforce.com/issues_view?id=a1p3A000000eshdQAA It's scheduled to be fixed in the next patch release. We've identified the exact set of circumstances that cause this to appear. Suppose you have n picklist values. If one of those picklist values is a number m < n, and that value is not the m th value created, ...


12

1 - Is their anyway we could create Custom Metadata in Test Classes? I tried to create on my Test Class but I got an error saying the fields of the metadata could not be writable. No, you can't create custom metadata in Apex Code. This is noted as a limitation of the feature in Custom Metadata Types: Custom metadata rows resemble custom object rows in ...


12

Both the EntityDefinition and FieldDefinition objects have a field called QualifiedApiName that does what I am looking for: MyMetadata__mdt mapping = [ SELECT SObjectType__r.QualifiedApiName FROM MyMetadata__mdt LIMIT 1 ]; system.debug(mapping.SObjectType__r.QualifiedApiName); // yields My_Object__c SObjectType s = Schema.getGlobalDescribe().get(...


10

You can deploy custom metadata records in changesets, but you have to add them to the changeset (which is different from just adding the type). In the "Component Type" dropdown, look for the name of your custom metadata type (In Summer 15, the Api Name; in Winter 16 it's the label). The reason for this: Suppose you had 10K records of a type. Why ...


10

Salesforce Developers put out the blog post Testing Custom Metadata Types that includes the section Testing Global Custom Metadata. ...add an extra field to your custom metadata type to indicate what sort of tests the type is active for. For example, you could add a Text field called TestCase__c to your type. You can leave this field blank for production ...


10

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: $...


9

Gosh! This works: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_custommetadata.htm#meta_custommetadata <types> <members>*</​members> <name>CustomMetadata</name> </types> I just had some invisible character ( &​#8203; Unicode Character 'ZERO WIDTH SPACE' (U+200B) http://...


9

This sounds like a bug. Please file a case for us. UPDATE: We're working on a fix.


9

Custom Settings and Custom Metadata types can't be referenced directly in Lightning Component Markup. You have to use Apex layer for it. Src: https://help.salesforce.com/articleView?id=custommetadatatypes_accessing.htm&type=5 I had created an idea for support of custom settings, might worth extending for support of custom metadata types.


8

Custom Metadata supports a limited SOQL syntax, and "OR" statements are not supported. From the documentation: Custom metadata types support the following SOQL query syntax. SELECT fieldList [...] FROM objectType [USING SCOPE filterScope] [WHERE conditionExpression] [ORDER BY field {ASC|DESC} [NULLS {FIRST|LAST}] ] The fieldList can include ...


8

I've done quite a bit of research on Custom Metadata Types vs Custom Settings, and I've found that in only a few cases are Custom Settings more useful. Custom Metadata types have a number of advantages that make them the correct choice to implement almost always. A lot of this has already been said, but some things have been added recently, so I thought I'...


8

The 00N prefix is the CustomField metadata object. Unlike the API name, the field's ID will never change once created. You can query this using the Tooling API: SELECT DeveloperName FROM CustomField WHERE Id = '00N...' You'll need to strip the object name off the front of the string before you query it. The DeveloperName field will be the API Name. ...


8

Yes, you're doing it right. Your code would look approximately like this: for(Account record: Trigger.new) { AccountGroup__mdt[] value = [select GroupType__c FROM AccountGroup__mdt WHERE GroupCode__c = :record.AccountGroup__c]; if(!value.isEmpty()) { record.Field__c = value[0].GroupType__c; } } Note that this is one of the few times where a SOQL ...


7

As stated above, you can't insert Custom Metadata via Apex, but you create instances of mock data via JSON deserialization. public static SObject getMetadata(SObjectType metadataSObjectType, Map<String, Object> fields) { /** * @Version-1.0.0 * Created. */ Map<String, Object> jsonFields = new Map<String, Object> {...


7

The Data Loader, as far as I can tell, does not support Custom Metadata (and we've been given no indication if this will be available in the future). In fact, custom metadata isn't "real" data, and is actually documented in the Metadata API documentation. You could choose to use Ant and build the appropriate files that way, or you can follow the other ...


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

There can be several reason of this deployment error. Possible reason is mandatory field is missed or the referenced metadata name is incorrect. Below is the working code to create and update Custom Metadata via Metadata namespace. Callback class:- public class CustomMetadataCallback implements Metadata.DeployCallback { public void handleResult(...


7

I actually just found the answer to this question here. The documentation states the following: When setting the value for relationship fields, use the qualified API name of the related metadata, not the ID. Thanks everyone!


7

As Custom Metadata Records are metadata you can use Force.com Migration Tool and deploy the destructive changes content of destructiveChanges.xml <?xml version="1.0" encoding="UTF-8"?> <Package xmlns="http://soap.sforce.com/2006/04/metadata"> <types> <members>CustomMetadataType.CustomMetadataTypeRecord</members> ...


7

Custom Metadata isn't just a drop-in configuration load/save system. It acts in most cases like other metadata objects and variables in Apex and is subject to exactly the same syntax and limitations. Most of the issues you have below have to do with Apex and SOQL syntax, rather than Custom Metadata as such. If the API name of your Custom Metadata record is ...


6

I guess it really depends on if the data you are querying is data, or metadata? I think you're possibly referring to using Custom Metadata Types as data rather than metadata? Whilst it's true that the limits are relaxed for SOQL queries for querying Custom Metadata, using Custom Metadata for data would be both challenging, and a waste of resources. For ...


6

I've written a lot of code with custom metadata and I haven't been particularly happy with any solutions I've seen online from Salesforce directly or otherwise. No, there is no way to create custom metadata from test code, nor should there be. It's metadata, and allowing custom metadata to be edited in code erodes the critical distinction between metadata ...


6

We don't yet support this. FieldDefinition only includes fields as defined on the object, not individual subfields. We are thinking about (but haven't yet ranked in our priority list) also allowing relationships to EntityParticle. EntityParticle would include any field or subfield on the object that is supported in a SOQL select clause.


6

My understanding is that the Metadata.DeployContainer is the collection of components you want to deploy via Apex. When you call removeMetadata(md) or removeMetadataByFullName(fullName) you are saying "Don't include those components in the collection if they are there" rather than "These are the components I want to delete". As it is currently (Spring '18 /...


Only top voted, non community-wiki answers of a minimum length are eligible