1

I am trying to delete custom metadata type records for CountryMapping__mdt

How to define the specific metadata type api name in the destructiveChanges.xml?

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>CustomMetadataType.CustomMetadataTypeRecord</members>
        <name>CustomMetadata</name>
    </types>
</Package>
3
  • There are some tips on retrieving and deploying Custom Metadata records here: salesforce.stackexchange.com/questions/102497/… . I don't think there is a way to retrieve or deploy all records for a particular Metadata Type. During retrieve, you can get all CustomMetadata using the * character. That should show you the individual CustomMetadata records and you could build a new package manually. Jul 13, 2020 at 23:42
  • Is the above not working? Make sure not to include__mdt for the CustomMetadataType when referencing CustomMetadataTypeRecord. Ex. <members>CountryMapping.UnitedStates</members> Jul 15, 2020 at 11:14
  • @KrisGoncalves My issue is if I do that it only deletes one record? Is there any way to delete all records for CountryMapping?
    – ebar
    Jul 15, 2020 at 14:11

1 Answer 1

1

Unfortunately, there's no easy way as you're not able to use * with the way custom metadata type records are referenced in package.xml. If you attempt to do so like below:

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

You'll get an error saying

No CustomMetadata named: CountryMapping.* found

This leaves you with only two ways to delete all the records of a Custom Metadata Type (which the first option is usually the only viable option)

  1. You specify each specific record line by line in your destructiveChanges.xml
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>CountryMapping.UnitedStates</members>
        <members>CountryMapping.OtherCountry</members>
        <members>CountryMapping.EtcCountry</members>
        <name>CustomMetadata</name>
    </types>
</Package>
  1. You delete the custom metadata type itself assuming there's no references in code. You could then redeploy just the object xml (with no records) if you'd like afterwards. Requires more steps and probably not viable assuming you're referencing it in code/something.
<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>CountryMapping__mdt</members>
        <name>CustomObject</name>
    </types>
</Package>

You must log in to answer this question.

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