I have just installed and configured Visual Studio Code. I have authorized my staging organization which contains a grip of apex classes and custom objects. How can I download the existing code into the newly created project?

I get no results with:

sfdx force:source:retrieve --sourcepath c:\Users\*****\Projects\****\force-app

2 Answers 2


Another option is to use the SFDX: Create Project With Manifest command in VS Code (equivalent to using sfdx force:project:create with the -x or --manifest option), which will create your project with a manifest/package.xml file, that includes wildcard selectors for all the custom code types: ApexClass, ApexComponent, ApexPage, ApexTestSuite, ApexTrigger, and AuraDefinitionBundle, as well as StaticResource. Once you've authorized to a dev org or sandbox org that has code in it, you can use SFDX: Retrieve Source in Manifest From Org within VS Code. You can right-click on the package.xml file or use the command palette to find the command. This command is equivalent to sfdx force:source:retrieve -x ./manifest/package.xml.

  • Nice -- Learned something! May 8, 2019 at 14:13
  • Thank you for you direction here, it was very helpful. May 8, 2019 at 19:54
  • Really helpful :) Aug 3, 2020 at 5:50

You don't need --sourcepath. It looks at where you are pointing and tries to pull items which match what you have there already.

What you do need is a package.xml file to get your entire metadata database; you might need help getting that file for your particular org.

Instead, you can do the following to get going with Apex or Lightning Component development:

force:project:create -n MyProject
cd MyProject
sfdx force:source:retrieve -m CustomObject
sfdx force:source:retrieve -m ApexClass
sfdx force:source:retrieve -m ApexPage
sfdx force:source:retrieve -m ApexClass
sfdx force:source:retrieve -m AuraDefinitionBundle
sfdx force:source:retrieve -m LightningComponentBundle

or you can use this nifty one-liner:

sfdx force:source:retrieve -m CustomObject,ApexClass,ApexPage,ApexTrigger,LightningComponentBundle,AuraDefinitionBundle

That will populate your source tree, and --sourcepath will work when it's pointed at one of those folders.

  • 4
    Just saw your version. PS you can combine -m params, like -m CustomObject,ApexClass,ApexPage,ApexTrigger,LightningComponentBundle,AuraDefinitionBundle.
    – sfdcfox
    May 7, 2019 at 18:09
  • 1
    I kinda like to spread out the code when teaching! May 7, 2019 at 18:22
  • 2
    Thank you this is very helpful. I wish I could mark two correct answers. May 8, 2019 at 19:53

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.