How to Copy your Org’s Existing Code to an SFDX Project

Pulling code from an existing sandbox or production org isn’t as easy as running sfdx force:source:pull . The easiest way I’ve found for getting code I want from a sandbox or production org is to create an unmanaged package with the assets I want. Please note: you still cannot get code from managed packages.

Part 1: Create an Unmanaged Package for Code you Want to Export

1.Go to setup and search for package

Jeff 1.png

2. Click on Package Manager

3. Click on New

jeff 2.png

4. Name your package. (In this example I called mine myPackage )

jeff 3.png

5. Click Add to add new assets to the package.

6. Select any components you want to add. Note: Change component type to see all of your assets.

Part 2: Pull the Unmanaged Package and Convert to DX Project compatible files.

Once you have your package created, it is time to pull that package from your org to your local machine and then convert it to a DX project.

0. If you haven’t already Create a New DX Project for these files to live in.

  1. run sfdx force:mdapi:retrieve -r <outputFolder> -p <packageName> -u <username>

2. Open the new folder and extract the zip file.

3. Run sfdx force:mdapi:convert -r <directoryOfExtractedZip> -d <outputDir> Note: You will have to put these in the appropriate force-appfolder.

jeff 5.png