[SalesForce] How to retrieve customFields on standard objects using Ant Migration Tool

Background

I'm trying to reset a dev org by using this ant script.

Most part of the customisations added by default are removed. However, I'm not being able to retrieve custom fields on Opportunity, Account and other standard objects.

I'm using this to get customfields :

<types><members>*</members><name>CustomField</name></types>

And this to get standard objects:

<types><members>*</members><name>CustomObject</name></types>

I've also tried:

<types><members>Account.*</members><name>CustomField</name></types>

and

<types><members>Opportunity</members><name>CustomObject</name></types>

Unsuccessfully

Question

How can I retrieve custom fields on standard object on ant migration tool?

Best Answer

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!

Related Topic