Salesforce Asked by Brian Miller on January 4, 2022
Although we use git repos to track all our projects, I oftentimes want to do another check against a production file before I overwrite it with an sfdx force:source:deploy
command (because as much as a git repo is kept up-to-date, you never know what renegade changes have been made to Production…)
Is there a simple sfdx
workflow or command to bring in that file and compare against my local project version? Context: I use VS Code and git for day-to-day development.
After installing the sfdx:source:diff
tool from @Mohith Shrivastava's response, you can use the --json
flag to return the locations of the remote and local files that VS Code uses to diff. You can then pass those files to git diff
to see the diff in the command line.
Here is the whole command:
SFDX_DIFF_JSON=$(sfdx force:source:diff -p force-app/main/default/classes/MyController.cls -u MyProductionOrg --json)
git diff $(echo ${SFDX_DIFF_JSON} | jq '.result.remote' -r) $(echo ${SFDX_DIFF_JSON} | jq '.result.local' -r)
Answered by bbbco on January 4, 2022
Have you tried using the Salesforce official Diff Feature on the Extension Pack for Salesforce
https://developer.salesforce.com/tools/vscode/en/user-guide/source-diff/
From the terminal, run sfdx plugins:install @salesforce/sfdx-diff.
After the installation is complete, @salesforce/sfdx-diff appears in the list of installed plugins when running sfdx plugins.
Use the vscode menu to take the diff
This requires enabling the preview flag from your vscode settings
Answered by Mohith Shrivastava on January 4, 2022
VS Code has an option to detect conflicts on deployment for non-source-tracked orgs. Go to Settings > Salesforce Feature Previews > Salesforcedx-vscode-core: Detect Conflicts At Sync. Note that this is still a limited feature, so some caution is advised.
In the interim, if I want to check for differences, I usually do:
git checkout -b temp-branch
git add force-app
git commit -m "temp commit for compare"
sfdx force:source:retrieve -p force-app
git diff
This gives me a line-by-line analysis of everything. I can also use --name-only
just to get a feel for which files are affected.
Answered by sfdcfox on January 4, 2022
1 Asked on September 13, 2020 by deployment-failure
3 Asked on September 8, 2020 by mvk1991
1 Asked on September 6, 2020 by vivian
1 Asked on September 5, 2020 by 84079616ytreza
dynamic apex dynamic vf component dynamic visualforce visualforce
1 Asked on September 2, 2020 by carl-johan-beurling
apex contentdocument contentversion custom object lightning web components
2 Asked on August 25, 2020 by salesforce-developer
marketing cloud marketing cloud connect marketing cloud connector marketingcloudapi sfmc business unit
0 Asked on August 21, 2020 by divya
2 Asked on August 17, 2020
1 Asked on August 14, 2020 by mohammed-aiyaz
0 Asked on August 12, 2020 by sid-fortunato
1 Asked on August 11, 2020 by ajfmo
1 Asked on August 5, 2020 by rob-cowell
2 Asked on July 26, 2020 by clyde-w
1 Asked on July 24, 2020 by user52080
2 Asked on July 24, 2020 by ayub
0 Asked on July 21, 2020 by bo-wang
Get help from others!
Recent Answers
Recent Questions
© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir