I have successfully connected VS Code and pushed to several different SF environments, including Trailhead, Developer, and Production. But I can't figure out how to push to a sandbox. It looks like you can't connect to a sandbox the same way you would with another org (using SFDX: Authorize an Org from the command palette), but when I do it directly from the command line sfdx force:auth:web:login -r https://test.salesforce.com/ it seems to work (I get a message in terminal that I've Successfully authorized <mySandboxUsernam> with org ID <myOrgId>)

But after authorizing, if I try to right-click on a folder to deploy, I don't get a contextual menu option of SFDX: Deploy Source to Org as I would when authorized with other instances. Is there any way to push code to a sandbox? I don't mind doing it from the command line if that's the only way, but I can't find any documentation on how to do it.


4 Answers 4


You need to use the force:source:deploy command (not available in the UI, as far as I can tell).

The basic syntax is as follows:

sfdx force:source:deploy -p source-dir/ -u username-or-alias

This should work fine from any terminal you open in VS Code.


sfdcfox layout out a good option. At time of writing, though, force:source:deploy is still in beta (as of Winter '19, API v45.0).

If you aren't comfortable with the beta designation, the other option is to convert from source form to metadata api form

sfdx force:source:convert -d targetDirectory

and then deploy using the metadata api

sfdx force:mdapi:deploy -d targetDirectory -u usernameOrAlias


I'm not sure how much of this is due to changes in the CLI and Extensions since Feb 2019, but what is now (May 2019) the case is:

  • The SFDX: Authorize an Org command in VS Code prompts for the login URL, allowing you to specify test.salesforce.org for a Sandbox.
  • The context menu item SFDX: Deploy Source to Org works for the defaultusername for the project. The SFDX: Authorize an Org command sets the authorized org to be the default for the project. But if you use sfdx force:auth:web:login -r https://test.salesforce.com --setdefaultusername you'll achieve the same result.
  • Towards the left side of the VS Code status bar, the default username for the current project is indicated (with a plug icon). You can click it and select a different, already-auth'd org to be the project default, auth to a new org and set it as the default, or spin up a new scratch org and have it become the default.

Yes! you can now source track changes between your project and dev sandboxes using source tracking for sandboxes beta feature - Track Changes Between the Project and the Sandbox (Beta)

Which means you can start using source:pull & source:push with sandboxes !

You must log in to answer this question.

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