0

Is there a way to grab only the field names of custom objects using the ANT Migration Tool? I'm able to grab information about the members of Custom Objects themselves from my package.xml file, but I'm trying to filter it down to grabbing only the custom fieldnames or the <fullName> tags.

Here's my package.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Account</members>
        <members>Opportunity</members>
        <members>Contact</members>
        <name>CustomObject</name>
    </types>
    <version>41.0</version>
</Package>

Maybe something like this?

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Account</members>
        <members>Opportunity</members>
        <members>Contact</members>
        <name>CustomField</name>
        <name>CustomObject</name>
    </types>
    <version>41.0</version>
</Package>
2
  • If you're working with a volume of fields that makes manually doing this unfeasible - I had to isolate a few thousand field descriptions from the .object metadata files, and found python to be pretty effective, directly parsing the .object files that you retrieve Commented Mar 19, 2018 at 21:03
  • Per @BrianMansfield's suggestion, it's also easy and quick to do it in Python with simple_salesforce just by calling the Describe API.
    – David Reed
    Commented Mar 19, 2018 at 23:01

1 Answer 1

1

No, it won't work that way, "name" can only appear once. Also, CustomField does not support wildcards. The best that you can do without making a huge manifest is to grab the entire object, via:

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

The wildcard will not retrieve standard objects, only custom ones.

If you want to just get the fields without the extras (e.g. workflow rules, list views, etc), you would build a package, and then retrieve it. Go to Setup > Create > Packages, and then add all of the custom fields. To retrieve it, use the sf:retrieve packageNames attribute:

<sf:retrieve username="${username}" password="${password}" serverurl="${serverurl}"
    retrieveTarget="src" singlePackage="true" packageNames="Fields" />

You can also do this with Salesforce DX, which I find so much easier to use:

sfdx force:mdapi:retrieve -s -r src -u sfdcfox -p Fields

Either way, the first time you do this, you'll get a package.xml inside your result folder that contains a package manifest with all the field names you can use in later scripts.

3
  • Has to be in ANT Tool. I don't have access to Salesforce DX. I may opt to do some post-processing on the extracted data instead. Thanks! Commented Mar 19, 2018 at 20:55
  • @murkywaters You can do it with the ant tool, too. But yes, building the package.xml by hand would be painful, building the package may also be painful if you have a ton of fields. I personally use replaceregexp in the ant library to strip out unwanted elements out of my objects: <replaceregexp flags="gs"> <regexp pattern="\s*&lt;(listViews|searchLayouts)&gt;.+&lt;\/\1&gt;" /> <substitution expression="" /> <fileset dir=".\\src\\objects"> <include name="*.object" /> </fileset> </replaceregexp>
    – sfdcfox
    Commented Mar 19, 2018 at 20:57
  • @murkywaters In this deletion code, (listViews|searchLayouts) are the elements I strip out; you can add more pipes to get even more values out of the way, like (listViews|validationRules|searchLayouts)
    – sfdcfox
    Commented Mar 19, 2018 at 20:59

You must log in to answer this question.

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