1

As per title, is it possible to just deploy an object to an org, without any fields on it?

This is a bit of an XY problem though.

I'm actually trying to create an object in a dev org based on an object in another org. It has a number of lookups to other objects, so those object also need to exist. The other objects also have lookups... and so on.

If I include the whole object in my package.xml file, it tries to include all the fields.

My idea was to shortcut this process by only including a stub of the parent object, meaning I don't have to go to many layers of dependency.

2
  • have you tried manually cutting out the fields from the retrieve result before doing the deploy? even though all the fields come down with the retrieve, there is nothing that will block deploying it after removing unwanted stuff Commented Jan 5, 2018 at 6:20
  • Yeah, and it generally works. It's just a fair bit of work because I have multiple orgs with different needs, so for each one I have to customise it, which is why I was hoping there's a way to automate this. My other option is to use an XSLT transform to remove any fields node with a referenceTo attribute.
    – Nick C
    Commented Jan 5, 2018 at 6:27

1 Answer 1

3

I personally use the built-in replaceregexp task in ant to do (something similar to) this. In my case, I prefer to remove the listViews and searchLayouts for all of my objects, because they've been more problematic than not. Here's the bit from my build.xml file:

<target name="strip">
    <replaceregexp flags="gs">
        <regexp pattern="\s*&lt;(listViews|searchLayouts)&gt;.+&lt;\/\1&gt;" />
        <substitution expression="" />
        <fileset dir=".\\src\\objects">
            <include name="*.object" />
        </fileset>
    </replaceregexp>
</target>

The basically just says "find <listViews>...</listViews> and <searchLayouts>...</searchLayouts> and remove them". For your purpose, you could change it to:

        <regexp pattern="\s*&lt;(fields)&gt;.+&lt;\/\1&gt;" />

If you have other stuff you want to remove, you can use the | symbol, as in the first example, to find various elements you want to remove.

This seems to be the easiest way to do this, and runs in less than two seconds for about 130 objects that we maintain in our CVS.

This means that you can then write a command like this:

ant retrieve-from-source strip deploy-to-target

Or however you prefer to have your build.xml configured.

3
  • Thanks @sfdcfox. I ended up using this with a pattern of actionOverrides|compactLayoutAssignment|compactLayouts|fieldSets|fields|listViews|searchLayouts|webLinks
    – Nick C
    Commented Jan 7, 2018 at 23:06
  • Is it possible to do something similar with SFDX deploy command?
    – Leto
    Commented Mar 18, 2022 at 14:25
  • 1
    @Leto You can use .forceignore to automatically ignore certain elements, like list views, if you want to skip during deployment/push/pull/retrieve. You can also use awk or sed to modify files, find to delete files, or write NodeJS scripts for even more complicated functionality. None of this is built in to SFDX, just as the replaceregexp command is an Ant built-in, rather than a Ant Migration Tool function.
    – sfdcfox
    Commented Mar 18, 2022 at 15:08

You must log in to answer this question.

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