2

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 '16 at 8:08
  • The error received is "Unknown SObject Namespace for Metadata" – SFDC Learner Nov 25 '16 at 15:10
1

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">
    <fields>
        <fullName>AccountOffLimitMonths__c</fullName>
        <externalId>false</externalId>
        <fieldManageability>DeveloperControlled</fieldManageability>
        <inlineHelpText>Lorem ipsum dolor</inlineHelpText>
        <label>Account Off Limit Months</label>
        <precision>18</precision>
        <required>false</required>
        <scale>0</scale>
        <type>Number</type>
        <unique>false</unique>
    </fields>
    <label>Off Limit Settings</label>
    <pluralLabel>Off Limit Settings</pluralLabel>
    <visibility>Public</visibility>
</CustomObject>

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>
    <protected>false</protected>
    <values>
        <field>AccountOffLimitMonths__c</field>
        <value xsi:type="xsd:double">12.0</value>
    </values>
</CustomMetadata>

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.

|improve this answer|||||
1

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,

cmTest.value='Account';

or

cmTest.value='MyCustomObject__c';

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.

|improve this answer|||||
  • 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=" – SFDC Learner Dec 1 '16 at 16:57
  • We're looking into this. – Avrom Roy-Faderman Dec 7 '16 at 16:31
  • Just edited the post above--sorry, should have closed this loop earlier. – Avrom Roy-Faderman Nov 28 '17 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.