0

I am new to VSCode.

I used the following to get all classes updated as per Org:

sfdx force:source:retrieve -x src/package.xml

After that I made some changes in a class in the deveoper console and saved it.

Then I made some changes in the same class in VSCode without retrieving changes from the Org and saved it.

The class get saved successfully and overwrites my changes made in the developer console without showing any issue.

How to prevent VSCode to save changes in the Org if the local copy is not in sync with Org?

5
  • 3
    Use only one tool to develop. There isnt any magical solution for your problem, you can write a script that will run on opening of vs code and will retrieve stuff always on startup, but it will create more issues in the future – user1974566 Aug 1 '19 at 7:08
  • 1
    I used to use Sublime Text earlier. It prevents me from saving the file from the editor if it is updated in the Org. So I need to take a refresh from Org and save it in the editor. Isn't there any extension or something available in VSCode to achieve the same behaviour? – वरुण Aug 1 '19 at 7:12
  • I have seen on other machines. The ForceCode plug-in can do this thing. I have ForceCode plug-in installed but do not see an error while overwriting. – वरुण Aug 9 '19 at 4:53
  • 1
    One solution is to check the difference before saving the code to org = ` SFDX: Diff File Against Org`. – Rahul Gawale Aug 28 '20 at 6:59
  • Thanks Rahul. We can do something like taking retrieval from Org before making changes also. But I need a solution when the developer misses that thing, the VSCode or the SFDX plugin should throw the error. – वरुण Aug 28 '20 at 16:03
2
+50

I built my own VSCode Extension that I use for the requirements until the Salesforce official extension pack supports this as Generally Available.

  • Allow quicksaving to org upon saving
  • If the code in the server is different than local copy the save is stopped and a compare view is given that shows the difference between local copy and server copy.

The extension is complementary to the official salesforce Extension pack and Salesforce CLI. You will need Salesforce DX CLI Installed at minimum to make it work.

In order to install the SalesforceDX Code Companion you will need below steps

  1. Open the command line terminal and enter the below command

    sfdx plugins:install mo-dx-plugin

Make sure that the plugins were installed by running sfdx plugins

  1. Install the SalesforceDX Code Companion from the VSCode Extensions marketplace.

  2. Navigate to UserSettings for Salesforce DX Code Companion Extension and make sure these two settings are enabled. AutoSave - This allows to Save to the Server Manageconflict - This allows manages conflicts.

  3. Switch off the Deploy on Save feature of the Salesforce Extension pack for VSCode so it does not interfere. This is found in the settings again.

2
  • Hi Mohit, Does it allow to merge conflict or it just shows the conflicts. – Banshi Lal Dangi Sep 5 '20 at 6:53
  • It shows conflicts and you can use the git to merge them up – Mohith Shrivastava Sep 5 '20 at 8:49
1

Automatic conflict detection is available in beta for some commands only: https://developer.salesforce.com/tools/vscode/en/user-guide/detect-conflicts :

Select File > Preferences > Settings (Windows or Linux) or Code > Preferences > Settings (macOS).

Under Salesforce Feature Previews, select Detect Conflicts At Sync. You can also enter conflict detection in the search box to find the feature and then enable it.

In this beta release, we have enabled conflict detection for the SFDX: Retrieve Source in Manifest from Org and SFDX: Deploy Source in Manifest to Org commands only. All manifest files that exists both in the org and in the local environment are checked for conflicts; files that don’t exist in both are not checked.

The Salesforce Extensions for VS Code developer team are currently working on a more complete "Conflict detection" feature on all commands, see GitHub issue here

2
  • Hi @shamnia, I tried it but it is not showing conflicts. – Banshi Lal Dangi Sep 5 '20 at 6:41
  • @BanshiLalDangi for issues with beta version for the commands from standard plugin, its better to log an issue on mentioned link for github repo. You can also check Mohith's answer about his own custom VS code extension – Shamina Sep 5 '20 at 6:51
-1

Go to Settings in VS Code & search 'save' & refer below image that I have added.

Check if highlighted checkbox is enabled in your case.

Just disable it & it won't override. Now when you save, it will get saved locally & not on org.

enter image description here

1
  • 1
    I want the code to be deployed on the Org on save and also need warning of overwriting. The VSCode shows warning on other machines but not able to see such on my machine. – वरुण Jul 21 '20 at 8:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.