I have a scenario where I need to deploy a brand new custom object only with specific custom field(s) to another org. The other org does not have that custom object at all.
I'm using sfdx for VS Code to retrieve and deploy. It uses the sfdx force:source:retrieve --manifest
and sfdx force:source:deploy --manifest
command.
Example :
If I retrieve and deploy only the custom field, first it will only retrieve the custom field without the custom object file and when it tries to deploy it will give me error that custom object is not found in target org. Which makes sense.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Burger__c.Burger_Type__c</members>
<name>CustomField</name>
</types>
<version>49.0</version>
</Package>
Output
=== Retrieved Source
FULL NAME TYPE PROJECT PATH
──────────────────────── ─────────── ─────────────────────────────────────────────────────────────────────────────
Burger__c.Burger_Type__c CustomField force-app\main\default\objects\Burger__c\fields\Burger_Type__c.field-meta.xml
Error (when deploying)
Entity 'Burger__c' not found
But even if I retrieve and deploy like this, it ignores what ever custom field I mention. If custom object is listed it will retrieve and deploy most of everything of that object as seen in output below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
<types>
<members>Burger__c.Burger_Type__c</members>
<name>CustomField</name>
</types>
<types>
<members>Burger__c</members>
<name>CustomObject</name>
</types>
<version>49.0</version>
</Package>
Output
=== Deployed Source
STATE FULL NAME TYPE PROJECT PATH
───── ──────────────────────── ──────────── ──────────────────────────────────────────────────────────────────────────────────
Add Burger__c.Burger_Type__c CustomField force-app\main\default\objects\Burger__c\fields\Burger_Type__c.field-meta.xml
Add Burger__c CustomObject force-app\main\default\objects\Burger__c\Burger__c.object-meta.xml
Add Burger__c.Brand__c CustomField force-app\main\default\objects\Burger__c\fields\Brand__c.field-meta.xml
Add Burger__c.Callories RecordType force-app\main\default\objects\Burger__c\recordTypes\Callories.recordType-meta.xml
Coming back to question :
Is there any neat way to deploy a brand new object with specific components or fields from one org to another using sfdx. Or my scenario is not very common and not important ?
SFDX INFO :
sfdx-cli/7.82.0-3d0c527ac6 win32-x64 node-v12.18.3
@oclif/plugin-autocomplete 0.1.5 (core)
@oclif/plugin-commands 1.3.0 (core)
@oclif/plugin-help 3.2.0 (core)
@oclif/plugin-not-found 1.2.4 (core)
@oclif/plugin-plugins 1.9.4 (core)
@oclif/plugin-update 1.3.10 (core)
@oclif/plugin-warn-if-update-available 1.7.0 (core)
@oclif/plugin-which 1.0.3 (core)
@salesforce/sfdx-trust 3.4.3 (core)
alias 1.1.3 (core)
analytics 1.12.1 (core)
auth 1.3.0 (core)
config 1.2.1 (core)
generator 1.1.3 (core)
salesforcedx 50.7.0 (core)
├─ schema 1.0.1 (core)
├─ templates 50.1.0 (core)
├─ @salesforce/sfdx-plugin-lwc-test 0.1.7 (core)
├─ salesforce-alm 50.7.0 (core)
├─ custom-metadata 1.0.10 (core)
└─ apex 0.1.4 (core)
sfdx-cli 7.82.0 (core)