CustomMetadata represents an individual record of a custom metadata type. It contains deployable configuration values that applications can read, including field values, a display label, and managed-package record protection.
It does not define the custom metadata type or its fields. That schema is represented by CustomObject and CustomField metadata, with the type's API name ending in __mdt. Retrieving or deploying records is separate from retrieving or deploying their schema.
Key Elements
| Element | What the Element Controls |
|---|---|
fullName |
Inherited component identity, using TypeDeveloperName.RecordDeveloperName. Omit the type's __mdt suffix in Metadata API component names. Include applicable namespaces on the type and record names independently. |
label |
The record's display text in the Salesforce user interface. It is not the component identity. |
protected |
A Boolean indicating whether the record is protected: true or false. Protection limits access and modification in managed packages and prevents changing a protected record's developer name after release. |
values |
A collection of field assignments, each represented by a CustomMetadataValue structure. Deploying this collection does not replace every field value on an existing record. |
field |
Within each values entry, the required, non-object-qualified custom field API name. Include its applicable namespace and __c suffix, such as picklist1234__AlphaSort__c. Do not prefix it with the custom metadata type name. |
value |
Within each values entry, the field value, interpreted according to the referenced field definition. It can be null. Entity and field relationship values use qualified API names, not record IDs. |
Behavior and Constraints
Creating custom metadata records requires the "Customize Application" permission.
Record protection and type protection are different
For a protected record in a managed package, access depends on which package contains the record, its type, and the code trying to read it:
- Code in the managed package containing the protected record can read it.
- Code in the managed package containing the custom metadata type can read records belonging to that type.
- Code in a managed package containing neither the type nor the protected record cannot read the protected record.
- Subscriber-created code and unmanaged-package code cannot read the protected record. Subscribers cannot read or modify it.
Records hidden by these rules are also unavailable through REST, SOAP, SOQL, and Setup. An apparently missing record can therefore reflect a visibility restriction rather than an absent component.
Developers can modify protected records through package upgrades or Metadata Apex classes, provided the Apex code is in the same namespace as either the records or their type. A protected record's developer name cannot change after release.
Record protection does not replace type protection. Subscribers cannot create records of a protected custom metadata type.
Omitted values do not clear existing values
Each values entry assigns a value to a field defined on the record's type. Omitting an assignment differs from explicitly assigning null:
- Existing record, omitted field: the destination keeps its previous value.
- New record, omitted field: the field value is null.
-
Explicit null:
<value xsi:nil="true" />clears the field to null.
Removing an optional field's values entry from a deployment does not clear that field in the destination. The same partial record definition can produce different results when creating a record and updating an existing one.
Values follow the field definition
Do not treat every value as a string. In declarative XML, the documented xsi:type encodings are:
- Checkbox:
xsd:boolean. - Date:
xsd:date. - Date/Time:
xsd:dateTime. - Picklist:
xsd:picklist. - Text, Phone, TextArea, URL, and Email:
xsd:string. - Number and Percent with scale equal to 0:
xsd:int. - Number and Percent with nonzero scale:
xsd:double.
Explicit typing avoids the documentation ambiguity described below. For example, a Checkbox assignment can use <value xsi:type="xsd:boolean">false</value>.
For fields that reference EntityDefinition or FieldDefinition, use the qualified API name of the target entity or field rather than a record ID. An entity value can be v1__SalesAgreement__c, with an associated field value of v1__CustomerReference__c. Interpret the field target in the context of its associated entity.
Deployment and Retrieval
Files and manifest members
In Metadata API format, records reside in the customMetadata folder and use the .md suffix. A record file can be named picklist1234__ReusablePicklist.Planets.md. The record name itself has no double-underscore suffix.
The package.xml manifest supports * for CustomMetadata. To select individual records, use complete component names as members, such as picklist1234__ReusablePicklist.Planets, under <name>CustomMetadata</name>.
The type and record names can have different package namespaces:
-
picklist1234__ReusablePicklist.Planetsidentifies a record on a type from thepicklist1234namespace. -
picklist1234__ReusablePicklist.travelApp1234__Hotelsidentifies a record from thetravelApp1234package on that same type.
Do not substitute a record ID, label, or unqualified DeveloperName for the complete component identity. Treat changing fullName as changing identity, not as updating an ordinary field; a reported Apex deployment created a second record instead of renaming the original.
Include the schema separately
A CustomMetadata deployment supplies record values. It does not create the custom metadata type or its field definitions. The destination must already have the corresponding schema, or the deployment must also supply it through the appropriate metadata components.
To retrieve the type definition, select its complete API name, including __mdt, as CustomObject metadata. For example, the schema for a type named ReusablePicklist__mdt is distinct from a record member named ReusablePicklist.Planets. Field assignments must match the type's CustomField definitions.
Retrieved number formatting
Retrieved values carry their appropriate types. Custom Number fields are stored as doubles, so a scale-0 value displayed as 1234567 can return through the API as 1234567.0. That representation difference alone does not indicate a configuration change.
Relationships
Record assignments reference custom fields, while authentication-provider and permission metadata can contain incoming record references. The connection to the type's CustomObject definition is a name-based schema association through the type portion of fullName, not a separate XML reference element.
References
-
CustomField:field, within eachvaluesentry.
Referenced By
-
AuthProvider:customMetadataTypeRecord, linking authentication-provider configuration to a custom metadata record. -
PermissionSet:name, within access-configuration entries associated with custom metadata. -
MutingPermissionSet:name, within access-configuration entries associated with custom metadata.
Interpret permission and muting references within their containing access entries. A name reference alone does not establish effective user access and does not bypass managed-package protection.
Documentation Inconsistencies
The CustomMetadata reference gives conflicting guidance about xsi:type: it explicitly permits omitting the attribute, then describes it as required for a CustomMetadataValue. Explicitly supplying the type that matches the field definition avoids relying on that conflicting wording. Use xsi:nil="true" when explicitly assigning null.
Reported Issues
-
Changing a record name can create another record rather than rename it. In a 2019 Apex Metadata API report, assigning a new record name through
fullNameinserted a second record. The answer attributed this to the underlying file-based deployment mechanism not performing component renames. This report does not establish identical rename capabilities for every management interface. Developer-name update discussion. -
A deployment job ID does not confirm that a record was saved. A 2022 discussion about creating and updating records from a Lightning Web Component described
Metadata.Operations.enqueueDeploymentreturning a deployment ID, with the outcome delivered later toMetadata.DeployCallback.handleResult. In that workflow, success and failure handling belongs to the deployment result, not the initial button response. Apex deployment result handling. -
CLI conversion can omit records that are still listed in the manifest. A 2024 report traced a missing
customMetadataoutput folder to an*.mdrule in.forceignore. A broad rule intended to ignore Markdown also matched the Metadata API record suffix. This was a packaging diagnosis, not evidence that the records were unsupported. Missing converted records discussion. -
A package can fail with missing-type Apex errors when only records were retrieved. In a 2024 second-generation managed-package report, retrieving
CustomMetadatadid not retrieve the type definition. The author reported resolving the schema omission by retrieving the namespaced__mdtcomponent asCustomObject, which brought back the type and its fields. Record-versus-schema packaging discussion. -
An unknown-type manifest error can come from an invisible character. In a 2015 retrieval report, a zero-width space copied into
CustomMetadatacaused the type name to be rejected. Replacing it with the plain ASCII name resolved the error. Manifest hidden-character diagnosis. -
Apex updates were reported to fail despite permissions assigned through a permission set. In a 2023 discussion, a user received
System.NoAccessException: Not allowed to install or modify metadata via Apexwith "Customize Application" and "Modify Metadata Through Metadata API Functions" assigned through a permission set. One respondent reported that assigning those permissions directly to a cloned profile resolved the failure in their org. This is a conditional workaround report, not a general requirement to grant permissions through profiles. Apex metadata permission discussion.
Common Questions
Does retrieving CustomMetadata retrieve the type and its fields?
No. CustomMetadata retrieves records. Retrieve the type's __mdt API name as CustomObject metadata for its schema; its fields are represented by CustomField metadata.
What fullName should I use for a custom metadata record?
Use TypeDeveloperName.RecordDeveloperName, omitting __mdt from the type portion. Include applicable namespaces independently on both sides of the dot. A label, record ID, or unqualified DeveloperName is not the complete identity.
How do I clear a custom metadata field during deployment?
Include the field assignment with <value xsi:nil="true" />. Omitting the field preserves its previous value on an existing record; omission produces null only when deploying a new record.
Why can't I see a protected custom metadata record?
Managed-package protection can hide it from subscriber code, unmanaged code, unrelated managed packages, APIs, SOQL, and Setup. Visibility depends on the package containing the record or its type, so absence from a query or Setup does not prove that the record is missing.
Why are custom metadata records missing after CLI conversion?
One reported cause is an *.md entry in .forceignore. Custom metadata record files use the .md suffix in Metadata API format, so a broad Markdown ignore rule can exclude them even when the manifest lists them.