Newer Version Available
Retrieve Source from the Scratch Org to Your Project
To run the retrieve commands described in the remainder of this topic, first open a terminal (macOS and Linux) or command window (Windows) and then change to your Salesforce DX project directory.
Preview a Retrieve
Before you retrieve metadata from an org, you can preview the components that will be retrieved, the potential conflicts, and the ignored files by executing project retrieve preview. For example, this command displays a preview of retrieving changed metadata from a scratch org with the alias MyGroovyScratchOrg to your local project.
Retrieve Metadata from Your Scratch Org
To retrieve changed source from your default scratch org to your project, run this command
The command displays what it retrieved and where in your local Salesforce DX project it puts it. This sample output shows a retrieve of the DiscountSpecial Apex class and DiscountPermSet permission set into the force-app/main/default directory.
Use flags to target the source you want to retrieve, rather than everything that’s changed.
- Use the --metadata flag to retrieve specific metadata components, such as Apex classes.
- Use the --manifest flag to retrieve components in a manifest file.
- Use --source-dir to retrieve source in a package directory.
See the reference information about project retrieve start for examples and other flags you can specify.
Select Files to Ignore During Retrieves
It’s likely that you have some files that you don’t want to sync between the project and scratch org. Add these files to the .forceignore file so they’re ignored by the retrieve command.
If the Retrieve Detects File Conflicts
During development, you change files locally in your file system and change the scratch org using builders and editors. Usually, these changes don’t cause a conflict and involve unique files. Also, the project retrieve start command doesn’t handle merges. Projects and scratch orgs are meant to be used by one developer.
However, if you run project retrieve start, and conflicts are detected, Salesforce CLI terminates the operation and doesn’t retrieve the source. Instead, it displays conflict information, such as this sample output. The PropertyController Apex class has been changed both locally and in the org, but the changes are in conflict.
First decide which change you want to keep. To keep the change that’s in the org, rerun the retrieve and specify the --ignore-conflicts flag.
To keep the local change, run the project deploy start command to deploy the change to your org, and specify the --ignore-conflicts flag.