Sub topic 2
Previewing Changes Before You Move Them
Assume you have a Salesforce DX project, the sf CLI, an authorized org, and basic knowledge of Apex metadata. This chapter uses a scratch org, which supports source tracking.
Previewing Changes Before You Move Them
Source tracking records the last synchronized state of your local project and the org. A preview compares that state with the current files and metadata. It shows what would deploy, what would retrieve, and whether conflicts exist.
sf project deploy preview --target-org my-scratch
sf project retrieve preview --target-org my-scratchThe deploy preview describes local changes. The retrieve preview describes changes made in the org. Neither command changes files or metadata.
Deploying Only Your Local Changes
After reviewing the deploy preview, deploy tracked local changes:
sf project deploy start --target-org my-scratchBecause the org is tracked, the CLI selects only components changed locally since the last synchronization. You do not need to list a source directory or metadata name.
Retrieving Changes Made in the Org
To bring tracked org changes into the project, review and run:
sf project retrieve start --target-org my-scratchThis command selects only metadata changed in the org. Retrieval can overwrite local files, so inspect the preview first and make sure local work is committed or otherwise backed up.
How Conflicts Arise
A conflict occurs when the same component changed locally and in the org since the last synchronized revision. For example, you edit MyClass.cls locally while another developer edits the class in the org. The CLI cannot safely choose which version should win.
Resolve the difference by comparing the versions, merging the intended content, and then synchronizing deliberately. The --ignore-conflicts option forces one operation to overwrite the other. Use it only after reviewing the preview.
Exercise
Which command shows local changes that would be deployed without changing the org?
Show answer
sf project deploy preview --target-org my-scratch