94 votes
Accepted

What are the object and field name suffixes that Salesforce uses? Such as __c and __x

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 ...
user avatar
75 votes
Accepted

What is the difference between Custom Settings and Custom Metadata Types

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 ...
user avatar
38 votes
Accepted

Insert Custom Metadata for Unit Test

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. ...
user avatar
26 votes

What is the difference between Custom Settings and Custom Metadata Types

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 ...
user avatar
22 votes

Insert Custom Metadata for Unit Test

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 ...
user avatar
  • 5,165
19 votes

Unit Test - Creating Custom Metadata

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 ...
user avatar
  • 13.2k
19 votes
Accepted

Eliminate query on Custom metadata type?

Edit: The rows themselves now count against the 50k SOQL row limit, although they do not count against the 100 SOQL query limit. To access custom metadata records without consuming SOQL rows is to use ...
user avatar
  • 429k
19 votes
Accepted

Custom Metadata vs. Custom Objects in Managed Package

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 ...
user avatar
  • 9,426
17 votes
Accepted

How can I get the API Name of a related EntityDefinition?

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 ...
user avatar
  • 142k
17 votes
Accepted

Custom Metadata types not supported in Apex Classes?

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
user avatar
  • 2,299
16 votes

Custom Metadata vs. Custom Objects in Managed Package

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 ...
user avatar
  • 85.9k
15 votes
Accepted

Mass Insert Custom Metadata

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" ...
user avatar
  • 429k
13 votes

What is the difference between Custom Settings and Custom Metadata Types

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 ...
user avatar
  • 1,437
13 votes
Accepted

Massive Spring '17 bug: SOQL returns wrong Custom Metadata Type picklist value

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 ...
user avatar
13 votes
Accepted

How to get a field's API name when querying a field of datatype, Metadata Relationship(Field Definition)

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 ...
user avatar
  • 429k
13 votes
Accepted

Qualified API Name returns null in Test context for Custom Metadata

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 ...
user avatar
  • 142k
12 votes

Unit Test - Creating Custom Metadata

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 ...
user avatar
  • 429k
12 votes

Eliminate query on Custom metadata type?

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 ...
user avatar
11 votes

Insert Custom Metadata for Unit Test

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 ...
user avatar
  • 13.2k
11 votes
Accepted

Custom MetaData Types reference in Formula Field

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 ...
user avatar
  • 429k
10 votes

Insert Custom Metadata for Unit Test

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<...
user avatar
  • 7,306
10 votes
Accepted

Custom Metadata types

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 ...
user avatar
10 votes

Unit Test - Creating Custom Metadata

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 ...
user avatar
10 votes
Accepted

Can I Create Child Custom Metadata records through the Metadata API?

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 ...
user avatar
9 votes
Accepted

Why do I get a DisjunctionsNotSupportedException when doing a SOQL query on Custom Metadata?

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 [...] ...
user avatar
  • 2,012
9 votes
Accepted

How to retrieve or deploy Custom Metadata Records by ANT Migration Tool?

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&...
user avatar
  • 13.2k
9 votes

Unit Test - Creating Custom Metadata

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 ...
user avatar
9 votes
Accepted

Deploying Metadata through Metadata.Operations.enqueueDeployment fails with a null message

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 ...
user avatar
  • 22.2k
9 votes
Accepted

Why are where clause comparison operators case-sensitive when using SOQL to query custom metadata?

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

Reference Custom Metadata Type from Lightning Component

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=...
user avatar

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