[SalesForce] sfdx force:source:push command failed. Source conflict(s) detected

  1. Run following command:

    sfdx force:source:push

Following error has been received:

ERROR: We couldn't complete the push operation due to conflicts. Verify th
at you want to keep the local versions, then run "sfdx force:source:push -f
" with the –forceoverwrite (-f) option.
STATE FULL NAME TYPE PROJECT PATH
──────── ───────────────────────── ───────── ───────────────────────────
───────────────────────────────────────
Conflict TransactionSyncEvent ApexClass forceApp/main/core/src/even
t/classes/TransactionSyncEvent.cls
ERROR running force:source:push: Source conflict(s) detected.

  1. sfdx force:source:push --json command returns following log:
{
"status": 1,
"result": [
{
"state": "Conflict",
"fullName": "TransactionSyncEvent",
"type": "ApexClass",
"filePath": "forceApp/main/core/src/event/classes/TransactionSyncEvent.cls"
}
],
"name": "sourceConflictDetected",
"message": "Source conflict(s) detected.",
"exitCode": 1,
"commandName": "SourcePushCommand",
"data": [
{
"state": "Conflict",
"fullName": "TransactionSyncEvent",
"type": "ApexClass",
Dmitriys-MacBook-Pro:myapp dmitriyprozorovskiy$ sfdx force:
source:push --json
{
"status": 1,
"result": [
{
"state": "Conflict",
"fullName": "TransactionSyncEvent",
"type": "ApexClass",
"filePath": "forceApp/main/core/src/event/classes/Transact
ionSyncEvent.cls"
}
],
"name": "sourceConflictDetected",
"message": "Source conflict(s) detected.",
"exitCode": 1,
"commandName": "SourcePushCommand",
"data": [
{
"state": "Conflict",
"fullName": "TransactionSyncEvent",
"type": "ApexClass",
"filePath": "forceApp/main/core/src/event/classes/Transact
ionSyncEvent.cls"
}
],
"stack": "sourceConflictDetected: Source conflict(s) detected.\n at
ALMError (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/salesfo
rce-alm/dist/lib/core/almError.js:44:19)\n at MetadataRegistry.initializ
eMetadataTypeInfos.then.then.catch.e (/Users/dmitriyprozorovskiy/.local/sha
re/sfdx/node_modules/salesforce-alm/dist/lib/source/sourceApiCommand.js:54:
31)\n at tryCatcher (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_m
odules/bluebird/js/release/util.js:16:23)\n at Promise._settlePromiseFro
mHandler (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebir
d/js/release/promise.js:517:31)\n at Promise._settlePromise (/Users/dmit
riyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/promise.
js:574:18)\n at Promise._settlePromise0 (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/promise.js:619:10)\n at Promise._settlePromises (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/promise.js:695:18)\n at _drainQueueStep (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/async.js:138:12)\n at _drainQueue (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/async.js:131:9)\n at Async._drainQueues (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/async.js:147:5)\n at Immediate.Async.drainQueues [as _onImmediate] (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/bluebird/js/release/async.js:17:14)\n at runCallback (timers.js:705:18)\n at tryOnImmediate (timers.js:676:5)\n at processImmediate (timers.js:658:5)\nOuter stack:\n at Function.wrap (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/@salesforce/core/lib/sfdxError.js:151:27)\n at SourcePushCommand.catch (/Users/dmitriyprozorovskiy/.local/share/sfdx/node_modules/salesforce-alm/dist/ToolbeltCommand.js:247:46)",
"warnings": []
}

Expected result
sfdx force:source:push executes successfully

VS Code Version:
Version: 1.41.1

SFDX CLI Version:
sfdx-cli/7.44.0-e77f9c8515 darwin-x64 node-v10.15.3 - latest version

OS and version:
OS: Darwin x64 18.7.0

enter image description here

Best Answer

This appears to be a bug. Running sfdx force:source:status -a (or "SFDX: View All Changes" in the VS Code plugin) shows you remote and local changes, but in this case reports remote changes even when the files are identical. You can verify this using the Source Diff plugin (currently in beta).

The quick and easy workaround is to use the -f "force" option in your push command (sfdx force:source:push -f, or look for "...Override Conflicts" in the VS Code command palette). But be aware you should also exercise caution when collaborating with other developers, so as not to override someone else's work.

Unfortunately this also makes the "push on save" feature redundant, but there is a workaround for that too. Using Multi-Command for VS Code you can configure a single keybinding to save and auto-push with the --force option.

1 - Install the Multi-Command for VS Code plugin using VS Code.

2 - Add the following to your settings.json

"multiCommand.commands": [
    {
        "command": "multiCommand.saveAndForcePush",
        "sequence": [
            "workbench.action.files.save",
            "sfdx.force.source.push.force"
        ]
    }
]

3 - Add the keybinding to your keybindings.json file (it's in the same directory as settings.json)

{
    "key": "Ctrl+Shift+s",
    "command": "multiCommand.saveAndForcePush",
    "when": "editorTextFocus"
}

This sets Ctrl+Shift+s as a hotkey to first save the file locally, then use SFDX force push. Change the hotkey as required (VS Code Keybinding docs for more details).

Related Topic