Use narrow deployments when fixing production issues, iterating on metadata, or validating a small change set. Salesforce deployment errors are easier to diagnose when the payload contains only the files required for the behavior under test.
- Deploy the smallest coherent unit.
- Run only the tests needed to prove the change.
- Avoid unrelated metadata churn.
- Keep validation and deployment commands reproducible.
- Identify every metadata member touched by the change.
- Include parent dependencies only when Salesforce requires them.
- Verify installed Salesforce CLI help for the command family.
- Validate first with
--dry-runfor ordinary narrow validation, orproject deploy validatefor production quick-deploy flow. - Use
RunSpecifiedTestsfor Apex changes when possible. - Deploy the same payload that passed validation.
- Re-check the affected UI or automation path in the target org.
Include:
- The LWC bundle directory when any LWC file changes.
- Apex classes, triggers, and matching tests.
- Custom fields used by new code.
- Quick actions, FlexiPages, object overrides, or tabs when UI activation changes.
- Permission sets when access is part of the change.
Avoid:
- Full object files when only a field changed, unless the project uses source tracking conventions that require them.
- Profile metadata unless the change explicitly depends on profile access.
- Record pages unrelated to the target experience.
- Formatting-only changes in generated XML.
sf project deploy start --dry-run --source-dir force-app/main/default/classes/ProjectService.cls --source-dir force-app/main/default/classes/ProjectServiceTest.cls --test-level RunSpecifiedTests --tests ProjectServiceTest --target-org myOrgFor production-style validation that returns a quick-deploy job:
sf project deploy validate --source-dir force-app/main/default/classes/ProjectService.cls --source-dir force-app/main/default/classes/ProjectServiceTest.cls --test-level RunSpecifiedTests --tests ProjectServiceTest --target-org myOrg --wait 30sf project deploy start --source-dir force-app/main/default/classes/ProjectService.cls --source-dir force-app/main/default/classes/ProjectServiceTest.cls --test-level RunSpecifiedTests --tests ProjectServiceTest --target-org myOrgWiden only when the validation error proves the payload is incomplete. Common examples:
- Apex references a field not present in the target org.
- A Lightning page references an action or component missing from the payload.
- A permission set references a field, class, or tab that is not included.
- A test depends on metadata shape that was changed in a separate file.
NoTestRunis not valid for production Apex deployments.RunSpecifiedTestsrequires each named test class to be deployable and selectable.- A class with no tests can still break a deployment if selected tests do not cover changed Apex enough.
- For UI-only metadata, validate without tests only when no Apex is being deployed and org policy permits it.
- A validation job is not a deployment until a matching quick deploy or real deploy succeeds.
- If a command times out or runs async, use
sf project deploy report --job-id <id>before claiming success or failure.