How to retrieve customFields on standard objects using Ant Migration Tool

As per the documentation the CustomField metadata type does not support wildcards sadly. You can access Custom Fields on Standard Objects by using the CustomObject metadata type as described here against specific Standard Objects. Then parse the .object file to build your destructiveChanges.xml file. Finally you can also use the sf:listMetadata task to download a list of all custom fields and then filter locally for Standard objects.

     <sf:listMetadata 
        username="${sf.username}"
        password="${sf.password}"
        metadataType="CustomField"/>

You might also be interested in an open-source undeploy Ant target published here, that wraps most of what i suspect your trying to develop up into a single Ant target. Sadly Salesforce do not yet give us a 'clean my org' task, so we build our own!


Fully naming the fields works e.g.:

<types>
    <members>Account.PayeeNameOverride1__c</members>
    <members>Account.PayeeNameOverride2__c</members>
    <members>Contact.JobDescriptionDate__c</members>
    <members>Contact.JobDescription__c</members>
    <name>CustomField</name>
</types>

If you want to extract all the custom field of say Accout object , then write atleast one custom field name of account object and then write * in the other member tag like this

<types>
        <members>*</members>
        <members>Contact.Level__c</members>
        <name>CustomField</name>
    </types>

This will extract all the custom field of account object.

And if you want to extract custom as well as standard field then go for this

<types>
        <members>Contact</members>
        <name>CustomObject</name>
    </types>

Hope it helps