9

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

  1. Is this possible?

I guess it should be possible if this is available for packages and changesets but can't find a way out to do this.

  1. How to do this?

Found some article about this here:

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_custommetadata.htm#meta_custommetadata

<types>
    <members>*</​members>
    <name>Custom​Metadata</name>
</types>

I see error

package.xml - Entity type: 'Custom​Metadata' is unknown
  1. Does anyone knows how to overcome this error?

This should be working since version 31 but it is not working even in version 35.0

  • check above...its same – Mohith Shrivastava Dec 15 '15 at 12:06
  • @MohithShrivastava I agree the question might sound similar but unfortunately it is not answered there. I know that I can do that by Change Set, but here question is if there is any way to do this by ant migration tool, it is not answered there – Patlatus Dec 15 '15 at 12:12
  • @MohithShrivastava if you are able to retrieve or deploy custom metadata records by ant migration tool, please share how do you do that – Patlatus Dec 15 '15 at 12:14
  • sure.Once I am infront of computer I will do this.For sure this is possible – Mohith Shrivastava Dec 15 '15 at 12:39
9

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>CustomMetadata</name>
</types>

I just had some invisible character ( &​#8203; Unicode Character 'ZERO WIDTH SPACE' (U+200B) http://www.fileformat.info/info/unicode/char/200b/index.htm ) copied from documentation between small 'm' and capitalised 'M':

<types>
    <members>*</​members>
    <name>Custom​Metadata</name>
</types>
| improve this answer | |
3

Following are the steps to deploy custom metadata using force.com IDE

1)Make sure to download the latest force.com Migration tool from your salesforce instance

Setup | Tools

enter image description here

2)Drop the ant-salesforce jar into your lib of the ANT directory

sample path--C:\Program Files\apache-ant-1.9.0\lib

3)Use proper package XML as shown below

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

4)Run the ant retrieve to fetch all custom metadata files enter image description here

5)Change the build.properties username and password to point to right instance and run ant deploy command

| improve this answer | |
  • Yes, thanks, everything I have done yesterday, and it didn't work for me since I copied the wrong code from documentation: <types> <members>*</​members> <name>Custom​Metadata</name> </types> only when I removed non-visible zero width space character it worked – Patlatus Dec 16 '15 at 13:18
3

Once you have Force.com Migration Tool set up, you can also choose to deploy individual CustomMetadata records using the following format:

<types>
    <members>MetadataObjectName.Record1Name</members>
    <members>MetadataObjectName.Record2Name</members>
    <name>CustomMetadata</name>
</types>
| improve this answer | |
0

Following on some of the answers above, I created this script to bring down all custom metadata records into your repo and convert to DX. These data records can be deployed into orgs like any other metadata and are available for inclusion in source control.

I followed the advice found here: https://success.salesforce.com/issues_view?id=a1p3A000000mD2iQAE&title=sfdx-when-using-pull-command-on-custom-metadata-types-you-see-an-error-custom-metadata-type-__mdt-is-not-available-in-this-organization

# Pull down all custom metadata records for a Salesforce org and unpack them into the DX format
# Run from the root of your Salesforce DX project, the script assumes that your project is a git repo
#!/bin/bash

mkdir .tmp

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

echo 'Retrieving metadata from Salesforce...'
sfdx force:mdapi:retrieve --retrievetargetdir .tmp/ --wait 5 --unpackaged .tmp/package.xml

echo 'Unzipping package...'
cd .tmp
unzip unpackaged.zip

cd unpackaged/customMetadata

echo 'Renaming md files to md-meta.xml...'
for f in *.md; do 
    mv -- "$f" "${f%.md}.md-meta.xml"
done

echo 'Moving metadata records...'
mv *.xml ../../../force-app/main/default/customMetadata

echo 'Cleanup...'
cd ../../..

rm -rf .tmp

git status 

echo 'Done!'
| improve this answer | |

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.