88

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


73

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


36

At time of writing, 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.


26

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


19

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


19

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. @...


19

Here are some "advantages" vs using a Custom Object: Can be Deployed Can use Field Definition or Entity Particle to create references to Custom Object Metadata Retrieve doesn't cost against SOQL limits (unless it contains long text) Can be referenced in formula fields Unit Testing isn't too bad as well as the code is well composed. Because they ...


18

No, you must access them with a SOQL statement. However, SOQL queries against custom metadata do not increase the SOQL queries governor limit counter nor the SOQL query rows governor limit counter, so you can query them as frequently as you like.


16

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(...


16

A reason I haven't seen articulated yet applies specifically to the managed package context: Packaged, protected Custom Metadata Types are an ideal solution for secret storage in a managed package context. While Protected Custom Objects and Protected Custom Settings can also offer secret storage, only Custom Metadata Types allow those secrets to be packaged ...


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, ...


13

You still need to use JSON construction if you want to set parent attributes without a true query for the records. Non Functional Code EntityDefinition sourceObject = [SELECT QualifiedApiName FROM EntityDefinition LIMIT 1]; MyMapping__mdt mapping = new MyMapping__mdt( Source_Object__r = sourceObject ); Error Field is not writeable: MyMapping__mdt....


12

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


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

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


11

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'...


11

There is possible hack to work around impossibility of insertion of custom metadata records. For this hack you just need to put query for custom metadata into separate property which should be settable for unit tests. @testVisible static List<Custom_Metadata__mdt> customMetadata { get { if ( customMetadata == null ) ...


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


11

Just An Update: Salesforce is coming up with new methods to retrieve custom metadata type records in a similar way custom setting records are retrieved. Yes, Without SOQL query. and It's happening in the Spring 21' release. Below is a glimpse of functionality from Spring 21' pre-release org.


11

getInstance method is a new addition that is supported on api version v51 and upwards. You need to update your DealTriggerHandler class api version to 51. Here is the relevant documentation


10

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> {...


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


9

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


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 is an old question, but one or two releases ago a new answer became available, so I thought I'd post it here. You now can instantiate custom metadata records, and set their values, the same way you would with records of any other type. You can't insert them, and they won't work with declarative platform features like formulas (just with Apex), but if ...


9

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(...


9

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


9

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!


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.


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