I want to update custom Metadata Relationship Field using Metadata API. I am using MetadataService.CustomMetadataValue to add the field and value parameters, but not successful in updating the Relationship field. Although I am able to update other custom Metadata Type field

Below is the code I am using

MetadataService.CustomMetadataValue cmTest = new MetadataService.CustomMetadataValue(); <br/>
cmTest.field='RelationshipField__c'; <br/>
cmTest.value= 'Id of the Parent Record';

Any help on this.

  • Did you get any error?
    – Reshma
    Nov 25, 2016 at 8:08
  • The error received is "Unknown SObject Namespace for Metadata" Nov 25, 2016 at 15:10

2 Answers 2


Are you updating an existing field? Or creating a new one and adding a value?

The CustomMetadata and the CustomObject are two different Metadata types, but under CustomMetadata you will find the "values of the fields created in the CustomMetadata" and under CustomObject you will find the CustomMetadata object itself.

For instance, a CustomMetadata named "Off Limit Settings" with a number field named "AccountOffLimitMonths" will be shown as a CustomObject like (file: objects/Off_Limit_Settings__mdt.object):

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
        <inlineHelpText>Lorem ipsum dolor</inlineHelpText>
        <label>Account Off Limit Months</label>
    <label>Off Limit Settings</label>
    <pluralLabel>Off Limit Settings</pluralLabel>

And the field will be shown under CustomMetadata as (file: customMetadata/Off_Limit_Settings.Off_Limit.md):

<?xml version="1.0" encoding="UTF-8"?>
<CustomMetadata xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <label>Off Limit</label>
        <value xsi:type="xsd:double">12.0</value>

If you want to add a new field, modify the first file and deploy it in a package. If you want to modify a field, use the second file.


You don't use IDs in the metadata API, but rather API names. Something like this should work:

MetadataService.CustomMetadataValue cmTest = new MetadataService.CustomMetadataValue(); <br/>
cmTest.field='RelationshipField__c'; <br/>
cmTest.value= 'ParentRecordName';

(I'm guessing here that it's a relationship between custom metadata types. If your domain is EntityDefinition, it'd be the entity name...e.g,




Update: It turned out that the above, while true, was only part of the issue here. There was also a separate problem contributing, which was a bug on our (Salesforce's) side which we fixed in Spring '17.

  • When I try this with the parent record Name, it gives the same error message "Unknown SObject Namespace for Metadata Error Id: 1700073871-578952 (-768177128) faultcode=soapenv:Server faultactor=" Dec 1, 2016 at 16:57
  • We're looking into this. Dec 7, 2016 at 16:31
  • Just edited the post above--sorry, should have closed this loop earlier. Nov 28, 2017 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .