1

I am trying to deploy a field on a custom metadata type using Ant.

Here's my package.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>*</members>
        <name>CustomMetadata</name>
    </types>
    <version>43.0</version>
</Package>

Then inside a customMetadata folder I have a file called nameOfMtdType.NameOfField.md. That file's content looks like this:

<?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">

    <values>
        <fullName>Number_Of_Balls__c</fullName>
        <description>The maximum number of balls that are allowed.</description>
        <externalId>false</externalId>
        <fieldManageability>DeveloperControlled</fieldManageability>
        <inlineHelpText>The maximum number of balls that are allowed.</inlineHelpText>
        <label>Number Of Balls</label>
        <precision>4</precision>
        <required>false</required>
        <scale>0</scale>
        <type>Number</type>
        <unique>false</unique>
    </values>
</CustomMetadata>

I am getting this error: Error parsing file: Element {http://soap.sforce.com/2006/04/metadata}fullName invalid at this location in type CustomMetadataValue

What am I doing wrong? The content inside the <values></values> is what I pulled from my scratch org using sfdx.

Also, I was trying to follow the documentation from this link: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_custommetadata.htm

Is there a better resource?

3

The Metadata API type CustomMetadata is for deploying records of Custom Metadata Types, not the schema of the type itself. That's why you're getting back that error - you supplied part of the type definition where Salesforce was looking for record data.

The Custom Metadata Type itself, along with its fields, is deployed as a CustomObject, where properties like fullName are expected. There's an example in that documentation of what it looks like to deploy a Custom Metadata Type field for a type called ReusablePicklistOption__mdt:

ReusablePicklistOption__mdt.object

<?xml version="1.0" encoding="UTF-8"?>
<CustomObject xmlns="http://soap.sforce.com/2006/04/metadata">
   <fields>
      <fullName>AlphaSort__c</fullName>
      <defaultValue>false</defaultValue>
      <externalId>false</externalId>
      <label>Sorted Alphabetically</label>
      <type>Checkbox</type>
   </fields>
   <label>Reusable Picklist</label>
   <pluralLabel>Reusable Picklist</pluralLabel>
   <visibility>Public</visibility>
</CustomObject>

The easiest way to handle this, though, is just to let Salesforce DX convert the source for you with the force:source:convert command. You can then trim the converted Metadata API source and package.xml down to deploy just the elements you're interested in, like this single field.

  • Thanks for the sfdx convert command, that's exactly what I used and then just deployed it using ant to the appropriate org. Saved me a ton of time! – Arthlete Aug 29 '18 at 23:13

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.