salesforcedx-vscode
salesforcedx-vscode copied to clipboard
File name mismatch with class name
Summary
I don't really know what is happening here. The file name is exactly the same as the class name and it is given me this error
I deleted this class from my org, and also deleted .sfdx. So why is it caching the old file name? I know it is not sfdx problem because I was able to deploy the class with the cli.
DSP_ContentDocumentLInkSelector.cls had a typo and I fixed it, but it seems the extension is caching the file name somewhere
Steps To Reproduce:
- Create a class with any name
- Ensure your class and the file names match
- Deploy it to any org using "SFDX: Deploy This Source to Org"
- Delete the class from that org
- Change the File Name and try to deploy it using "SFDX: Deploy This Source to Org"
- Verify this error happens
- Delete .sfdx and expect this will fix the issue
- try to deploy the class again using "SFDX: Deploy This Source to Org"
- verify the error persists
- Try to deploy your class again, but this time using the following cli command "sfdx force:source:deploy -m "ApexClass:YOUR_CLASS_NAME"
- Verify it worked! WHYYYYY!
Expected result
"SFDX: Deploy This Source to Org" should deploy my class when File Name and Class Name match
Actual result
"SFDX: Deploy This Source to Org" is not deploying the class because it thinks its file name does not match with the class name
Additional information
Salesforce Extension Version in VS Code: v52.17.0
SFDX CLI Version: sfdx-cli/7.120.0 win32-x64 node-v14.18.0
OS and version: Windows 10
A few questions on this one, as I haven't been able to reproduce the issue. In step 4, did you delete the class in the org directly, or by right clicking the class and either using 'Delete' or using SFDX: Delete from Project and Org? Then in step 5, did you rename the class name and make the edit in the class file as well? Lastly, do you have Override Conflicts On Push
enabled in your VS Code settings? (I'd give it a quick try if not to see if that resolves your issue).
I happen to have a very similar issue.
I created class called "consumerInteractionsViewController". Only few days later following active development I figured that the name is incorrect - first latter must be Capitalized, so correct name is: "ConsumerInteractionsViewController".
I tried to re-name the class name and file in VS Code. Upon deployment I got error:
Force-app/main/default/classes/consumerInteractionsViewController.cls File name mismatch with class name: ConsumerInteractionsViewController
I then tried deleting the class from VS Code using "Delete from Project and Org" and re-creating the class again from VS Code. Same problem.
I then deleted the class from everywhere - VS code and from the actual org using developer console. Re-created class with proper name from the developer console. Retrieved the metadata in VS code. Tried saving file - same error.
Edit: the problem could only be solved by starting new SFDX project and re-creating class. So there's definitely something cached there.
@randi274
in Step 4 I deleted the class using the Developer Console. In Step 5 I renamed the file, copied the file name, then I pasted it inside the class instead of typing it again.
I don't have Override Conflicts On Push
turned on, but I think the problem is not related to it because the class does not exist in the org. The experiment that I did showed that I was able to deploy the class using sfdx and I did not pass the -f flag to it.
I then deleted the class from everywhere - VS code and from the actual org using developer console. Re-created class with proper name from the developer console. Retrieved the metadata in VS code. Tried saving file - same error.
Exactly and it's annoying.
I was able to reproduce it, and I'm opening a bug for my team to track.
This issue has been linked to a new work item: W-10273785
I run into this issue after renaming files sometimes. If you deploy to org from the left hand side in the file structure instead of the editor window it works.
@AllanOricil I think the issue is that the name of the file doesn't match the class's name, and this isn't related to deleting or caching. Here's what I just did:
- I authenticated into my org
- In
/force-app/main/classes
I right-clicked, and selected "SFDX: Create Apex Class" - I gave it the name of
TestClass
- I then right-clicked on TestClass.cls, selected Rename, and then renamed it to
NewTestClass.cls
- I then right-clicked on TestClass.cls-meta.xml, selected Rename, and then renamed it to
NewTestClass.cls-meta.xml
At this point, the name of the files are NewTestClass1
, but within the file, the name of the class is still TestClass
:
public with sharing class TestClass {
public TestClass() {
}
}
- I then right-clicked on the file, and selected "SFDX: Deploy Source to Org"
At this point, I got the error you reported, " File name mismatch with class name". Is this the issue you are seeing, or is it something else?
@AllanOricil I think the issue is that the name of the file doesn't match the class's name, and this isn't related to deleting or caching. Here's what I just did:
- I authenticated into my org
- In
/force-app/main/classes
I right-clicked, and selected "SFDX: Create Apex Class"- I gave it the name of
TestClass
- I then right-clicked on TestClass.cls, selected Rename, and then renamed it to
NewTestClass.cls
- I then right-clicked on TestClass.cls-meta.xml, selected Rename, and then renamed it to
NewTestClass.cls-meta.xml
At this point, the name of the files are
NewTestClass1
, but within the file, the name of the class is stillTestClass
:public with sharing class TestClass { public TestClass() { } }
- I then right-clicked on the file, and selected "SFDX: Deploy Source to Org"
At this point, I got the error you reported, " File name mismatch with class name". Is this the issue you are seeing, or is it something else?
@jeffb-sfdc look at the first print screen I posted. I'm sure it is not that because I did update the file's name and its class name. I'm sure It is a bug from vscode because I was able to deploy my class using sfdx with no problem.
@AllanOricil I'm following your steps verbatim, and when I follow what's listed (eg w/o renaming the name of the class within the file), I get the "File name mismatch" error, which is expected. Here are the steps you listed:
- Create a class with any name (I named it, "INK.cls")
- Ensure your class and the file names match (they did)
- Deploy it to any org using "SFDX: Deploy This Source to Org"
- Delete the class from that org
- Change the File Name (I changed "INK.cls" to "Ink.cls" and "INK.cls-metadata.xml" to "Ink.cls-metadata.xml")
- try to deploy it using "SFDX: Deploy This Source to Org"
- Verify this error happens -> It did, and this is expected. The name of the class needs to match the name of the file.
- Delete .sfdx and expect this will fix the issue
-> It should should not fix the issue. The name of the class needs to match the name of the file. At this point the filename is "Ink.cls" but the class (what's defined in the source file) is
public with sharing class INK
.
On the other hand, if I also rename the name of the class (as well as the filename), and perform these steps, it deploys successfully:
- Create a class with any name (I named it, "BLOT.cls")
- Ensure your class and the file names match (they did)
- Deploy it to any org using "SFDX: Deploy This Source to Org"
- Delete the class from that org
- Change the File Name (I changed "BLOT.cls" to "Blot.cls" and "BLOT.cls-metadata.xml" to "BLOT.cls-metadata.xml")
- Open Blot.cls, rename the class name and the name of the constructor, and save the file. The contents of the file is now:
public with sharing class Blot {
public Blot() {
}
}
- try to deploy it using "SFDX: Deploy This Source to Org"
- Verify this error happens -> It did not happen. The class was successfully deployed to the org.
There must be a step missing here in order to repo. I'd like to fix this, but I first need to reproduce it.
@jeffb-sfdc I don't think you saw the print screen. Could please see the print screen, and then see that my class name, as well as it's file name are matching. I took that print screen and added YELLOW rectangles on the information that is important to understand that there is a bug. Inside those rectangles you will see that I'm not doing the mistake you think I'm doing. Besides that, even without seeing my print screen, you would notice that there is something wrong, as I was able to deploy the same class with sfdx but not with vscode.
@jeffb-sfdc Look closely to the output that vscode extension displayed on my ps. The PATH that the extension is trying to deploy is one that no longer exists in my project. That itself should explain the bug. Somehow the extension is using and old workspace/dir. This is why I think there is something being cached.
@jeffb-sfdc on step 5 I should have said that I had also changed its class name. Which I did, as shown in the Print Screen. Sorry for that, my bad.
This has been fixed and should go out in next week's build, 55.4.0. I found that after renaming a file (just changing case) updating the Apex class name, and then within the editor running the SFDX: Deploy This Source to Org
command, that I was able to reproduce it.
The issue was that after renaming a file (just changing the case), that VS Code's APIs pass the stale/previous URI. For us that's an issue b/c when an Apex class is deployed with a class name of myClass.cls
but the file name (which we get from MS's VS Code) is the old myclass.cls
, it's an issue b/c the names don't match. I added a fix to make an extra hop and go out and retrieve the file name from the file system before the command is executed.
Some other things worth mentioning:
- This doesn't repro from the explorer, the
SFDX: Deploy Source to Org
command is executed. - This doesn't happen if the contents of the file's name are change (characters are added or removed)
@jeffb-sfdc great job
@jeffb-sfdc - I'm on version 55.8.0 and still seeing this incorrect behavior when I rename a class only changing the case. Any thoughts?
OK, I saw in the change log that this fix was reverted in 55.4.1. Any update on when it might be fixed again?
For anyone trying to work around this issue, until the fix returns: I'll mention that I managed to get into a pretty frustrating state where I knew a particular class was identical between my local copy and a sandbox org, but I could neither Diff File Against Org nor Deploy This Source to Org from VS Code because the case of the class name and file name had been altered.
The workaround was to delete the local copy using the Explorer (both .cls and .cls-meta.xml), then restart VS Code, then retrieve the source from the org again.
@tmill21-umd We release version 56.3.1 last week and that should have the fix in it. We verified the fix was in the release and was working on windows before we published to the marketplace. Please install the latest version and let us know if the issue persists.
If you still encounter the issue after updating:
- Please let us know. We believe this has been fixed (we don't experience it anymore) and if it hasn't been fixed we want to know and get a fix in.
- This issue is that when renaming a file, Visual Studio Code hangs on to the old file name and passes that to the extensions. This is only an issue when renaming the file and only changing the case of the characters. If characters are added or removed, Visual Studio Code passes the correct file name. A work around that I used was 1. rename the file and add extra characters, 2. rename the file again, removing the extra characters, and updating the characters to the correct casing, 3. deploy
I am on version 56.5.1 and I am still seeing this issue with a Visualforce page that was renamed locally (and also renamed directly in the org to match) where the only change in the filename was some uppercase to lowercase letters.
I am also still facing the same issue, it is only changing a file name case that seems to be causing it.
Still not fixed... Getting this issue where the Apex Class file is the same in both Salesforce and VSCode
Hi @apj3nk1n5on @tom5491 Could you please create a new bug in Github issue with details including reproduce steps so that we could look into it? This issue has been closed.