Sub topic 6
Previewing Changes Before You Move Them
This chapter assumes you have a Salesforce DX project, the sf CLI installed, and a tracked org (such as a scratch org) that you have authorized. You should also know basic Git and command-line usage.
Why preview first
In a tracked org, the CLI knows which components changed locally and which changed in the org. A deploy or retrieve moves only those components. A preview shows you that list before anything moves. It changes nothing in your project or in the org.
Run a preview before every deploy or retrieve that you did not plan carefully. It catches unexpected files, files you meant to ignore, and conflicts.
The two preview commands
Each direction has its own command.
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchdeploy previewcompares your local project to the tracking state. It lists the local changes that would deploy.retrieve previewlists the org changes that would come down to your project.
Both commands also report conflicts and ignored files. Neither command writes anything.
Reading the output
The output groups components in tables. Exact columns vary by CLI version, but you will see these ideas.
| Group | Meaning |
|---|---|
| Will deploy / will retrieve | Components that changed on the source side and will move. |
| Conflicts | Components changed on both sides since the last sync. The command will refuse to move them unless you override. |
| Will delete | Components removed on the source side that will be removed on the target. |
| Ignored | Files matched by `.forceignore`. They never move. |
Each row shows the component type, name, and file path. Check the Conflicts group first. A conflict means someone changed the same component in the org and in your project.
A worked example
Suppose you edited MyClass.cls locally, and a teammate changed a validation rule in the scratch org.
- Run
sf project deploy preview --target-org my-scratch.MyClassappears under will deploy. The validation rule does not appear, because you did not change it locally. - Run
sf project retrieve preview --target-org my-scratch. The validation rule appears under will retrieve. - Run
sf project retrieve start --target-org my-scratch. The rule arrives in your project. - Run
sf project deploy start --target-org my-scratch. OnlyMyClassdeploys.
If you had also edited that same validation rule locally, both previews would list it under Conflicts. You would then decide which version to keep before moving anything. The next chapters cover that.
Common mistakes
- Using preview on an untracked org. Without tracking, the CLI cannot compute changes. Use
--source-dir,--metadata, or--manifestinstead. - Reading only one preview. The deploy preview does not show org-side changes. Run both before a sync.
- Overriding conflicts without looking.
--ignore-conflictsmakes one side overwrite the other. Use it only after you have read the preview. - Expecting ignored files to appear as changes. If a file is missing from the list, check
.forceignore.
Exercise
You edited an Apex class locally. A preview run with sf project deploy preview lists nothing to deploy. Name two likely causes.
Show answer
The file matches a pattern in .forceignore, so the CLI skips it. Or the org is not tracked, so the CLI cannot compute changes. A third cause is that you edited a file outside the package directories in sfdx-project.json.