Rename refactoring across files leads to requirement to "Force Save" one or more files

Issue #1115 resolved
Alan Birchenough created an issue

Consider a class A that calls method X on class B. If I open class B in the editor and rename the method X to Y, it is correctly renamed in both class A and class B. Then I execute "Save All". (My understanding of "Save All" is that it undertakes to save all "dirty" edit sessions, i.e., those that have changes in memory but not on the file system, let alone in Salesforce. In this case, both class A and class B should be dirty after the refactoring.)

When I execute "Save All", only class B is saved. If I now rerun class A, it fails with a compilation error saying "method does not exist, or incorrect signature". If I try "Save All" with class A open in the editor, nothing happens. Instead I have to use "Force Save" to push class A to the server, then everything is OK again. This is all clumsy enough if there are only two files involved, but if there are more, which there might well be for a rename refactoring, it becomes a bit of a nightmare.

Is there a better way?

Comments (4)

  1. Scott Wells repo owner

    Yes, after a rename refactoring that spans multiple files, use the Deploy Modified Metadata action to push all changed files to the server. You don't want to use the Save All action because that only saves either the currently active file or the "dirty" files (modified in the IDE relative to their filesystem counterparts) based on configuration. The various actions for deploying metadata and how they work are documented at the top-right of this page:

    TL:DR, you should use Ctrl+S/Cmd+S (i.e., Save All) when you're iterating in a single file. You should use Deploy Modified Metadata when you're making changes to multiple files due to refactoring, global search/replace, updates from version control, etc. You should use Deploy All Metadata if for some reason Deploy Modified Metadata fails due to, for example, undetected transitive dependencies.

    Hope that helps!

  2. Alan Birchenough reporter

    It does. These nuances were not at all obvious to me before. I have re-read the relevant documentation. I guess you can close it, but if "Save All" is really only useful for one file it is very confusing that it is called "Save All" and not "Save". In virtually every other application I have ever worked in, "Save All" means "save everything I need to save at this point".

  3. Scott Wells repo owner

    Yeah, I understand the confusion. Save All is a standard IntelliJ IDEA/WebStorm action that means "commit all unsaved editors to disk". IC piggy-backs on that when deploy-on-save is enabled to push that files/those files to the server. Then the bulk actions are more analogous to performing either an incremental or full build of your metadata against the server. I agree, though, that the terminology is a bit confusing.

    One of the items that I have included in the upcoming deployment/retrieval-themed release is allowing the user to configure the overridden Save All action to run Deploy Modified Metadata for the current module or project with no intermediate dialog required. The current behaviors (deploy current file/deploy files committed to disk) would continue to be available options since they tend to be more efficient for fast iteration, but my guess is that once it's available, most folks will likely want to have it do a background Deploy Modified Metadata. That's a bit of a preview of what's coming and how it should address this terminology impedance mismatch.

  4. Log in to comment