Skip to main content
3 of 5
deploy "to production" added
Brian Miller
  • 5.3k
  • 4
  • 38
  • 69

The "SFDX: Deploy Code to org" command uses the sfdx force:source:deploy command, which according to the documentation only deploys to non-production orgs (at least as of Spring '19).

A nifty way to deploy to production with these new commands (as inspired by the documentation above) is as follows:

  1. Set the SFDX_MDAPI_TEMP_DIR environment variable to a place that's easily accessible (like the metadata folder within your current project):
SFDX_MDAPI_TEMP_DIR=/path/to/mydxproject/metadata 
  1. Retrieve the exact metadata you want to deploy to production, like as follows:
sfdx force:source:retrieve -m ApexClass:MyUtilClass,ApexClass:MyUtilClass_Test -u MySandboxOrg 
  1. This will create a folder within your metadata folder with the metadata .zip file or package.xml file that you're looking for. Deploy from the zip file as follows (and feel free to add any other helpful options as specified in the mdapi Commands):
sfdx force:mdapi:deploy -f ./metadata/sdx_sourceRetrieve_1554058974901/unpackaged.zip -u MyProductionOrg 
  1. Check your deployment status in the production org itself or via mdapi:deploy:report

This allows you to use the new force:source:retrieve command and have it auto-convert into metadata, without having to call force:source:convert manually

Brian Miller
  • 5.3k
  • 4
  • 38
  • 69