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.
1sf project retrieve preview --target-org MyGroovyScratchOrgRetrieve Metadata from Your Scratch Org
To retrieve changed source from your default scratch org to your project, run this command
1sf project retrieve startThe 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.
1Preparing retrieve request... ⣟
2Preparing retrieve request... Succeeded
3
4Retrieved Source
5====================================================================================================================
6| State Name Type Path
7| ─────── ─────────────── ───────────── ────────────────────────────────────────────────────────────────────────────
8| Created DiscountSpecial ApexClass force-app/main/default/classes/DiscountSpecial.cls
9| Created DiscountSpecial ApexClass force-app/main/default/classes/DiscountSpecial.cls-meta.xml
10| Created DiscountPermSet PermissionSet force-app/main/default/permissionsets/DiscountPermSet.permissionset-meta.xmlUse 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.
1sf project retrieve start
2Preparing retrieve request... ⣾ Sending request to org
3 STATE FULL NAME TYPE FILE PATH
4 ──────── ────────────────── ───────── ───────────────────────────────────────────────────────────────────
5 Conflict PropertyController ApexClass <dir>force-app/main/default/classes/PropertyController.cls-meta.xml
6Preparing retrieve request... Error
7Error (1): There are changes in your local files that conflict with the org changes you're trying to retrieve.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.
1sf project retrieve start --ignore-conflictsTo keep the local change, run the project deploy start command to deploy the change to your org, and specify the --ignore-conflicts flag.
1sf project deploy start --ignore-conflicts