3

I have a question around SFDX source deploy to non-scratch org, with destructive changes using CI/CD pipeline:

## Authenticate with your playground or sandbox environment
$ sfdx force:auth:jwt:grant -i $CONSUMER_KEY -f assets/server.key -r $SF_TARGET_URL -u $USERNAME -a TARGETOrg

## Deploy source to sandbox org (This is with source code, all files, etc)    
$ sfdx force:source:deploy -l $TESTLEVEL -g -u TARGETOrg -w 180 -x ./manifest/package.xml

force:source:deploy does not consider destructive changes so delete metadata. I can use: $ sfdx force:source:delete -g -u TARGETOrg -m ./manifest/destructivechanges.xml and $ sfdx force:source:delete -g -u TARGETOrg -m ./manifest/destructiveChangesPre.xml

before and after force:source:deploy. But these would be three different transactions. If something goes wrong in the deploy command, the next statement won't execute. This is something which is not correct.

I don't want to do mdapi commands to deploy. How is this possible using source:deploy?

5

No, you can't use destructive changes with force:source:deploy. Instead, you would need to use Unlocked Packages. Create a package version that includes all the metadata, then create a new version with the items to be deleted removed from the package. Install the first package, which then associates the contents with the unpackaged metadata, then install the new version with --upgradetype Delete to cause the items to be deleted. A package install counts as a single transaction (for creating new elements, updating existing elements, and deleting old elements), thus providing you with the atomic transactions you're looking for.

| improve this answer | |
  • 1
    When you say "Create a package version that includes all the metadata, then create a new version with the items to delete", do you really mean "...then create a new version with items deleted from the new version of the package" – Brian Miller Dec 12 '19 at 19:23
  • 1
    @BrianMiller Yes, that is clearer. I'll revise :p – sfdcfox Dec 12 '19 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.