SFDX Quick Tip: Pulling source from a Sandbox into an SFDX project.

TL;DR: The easiest way is to create an unmanaged package.

  1. Create an unmanaged package with everything you want to move over.
  2. Convert the unmanaged package with the SFDX CLI
  3. Push to a Scratch Org

Create the unmanaged package

Setup > Quick Find > "Package" > Create > Packages

Jeff 1.png

Next Select the files you want:

 

Jeff 2.png

Retrieve the package with the CLI:

sfdx force:mdapi:retrieve -s -r {{pathToCreatePackageFile}} -u {{sandboxUsername}} -p {{packageName}}

Example:

mkdir package

sfdx force:mdapi:retrieve -s -r package/ -u jeff@salesforce.com -p sfdxTransfer

You’ll then get a package in the directory you specified.

Convert the package to an SFDX project

With SFDX: sfdx force:mdapi:convert -r package/

This will create new files from the old package data.

Push to a Scratch Org

And last step is to push to a scratch org.

sfdx force:source:push will push to your default scratch org.

You will likely get an error or two, just read through and resolve. For example if you’re missing a field on an object you will have to create that in your scratch org. Use sfdx force:org:open to open your scratch org and sfdx force:source:pull to pull changes that you make.