Looks like I have found already a culprit here.
It is very important to check sourceApiVersion
property of project.json configuration.
Looks like this value was 44.0
in my project. Probably because I have created it before updating the salesforce-cli tool. Then I updated the CLI and even reinstalled it but the project version has not been changed.
{
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
"namespace": "",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": /*"44.0"=>*/"45.0"
}
Now after updating this configuration settings, it started working successfully.
GIT: Clone on VS Code. Directory selected ../Documents/Demo-Project/force-app. A folder named remote-project is created with the source content from bitbucket. Got a pop up asking for Open Repository and Add to Workspace. I clicked on Add to Workspace.
This is your issue. You're creating an SFDX project, and then cloning a different SFDX project inside it. When you complete this step, your directory tree probably looks like this:
Demo-Project/
force-app/
main/
default/
aura/
remote-project/
.git/
aura/
democmp/
Only the folder enclosing .git
and its descendants are part of the Git repository, because that's where you chose to clone it. Git cannot see anything outside the repo boundary, so anything that is saved in main/default/aura/
isn't part of the repo and isn't visible to Git.
Conversely, you've told Visual Studio Code, by creating an SFDX project, that you want to be working in an outer directory tree rooted at force-app
. If you look in your sfdx-project.json
file, you should see something like
"packageDirectories": [
{
"path": "force-app",
"default": true
}
],
This tells VSC that your project's primary source directory is under force-app
(not remote-project
), and that's where your SFDX commands are going to save and push source from by default.
If you're starting from an existing SFDX project that's stored in a source code repo, which sounds like it's the case although I suspect something's a little off about the way you're discussing the folder tree, you probably want to just clone that project and then open its root folder in Visual Studio Code, rather than creating a new project locally first.
Best Answer
The error means you're missing a metadata file. On the file explorer, click on the New File button, and name it:
And give it the following contents:
Save, then deploy your class again.
Odds are, the file may have been accidentally deleted or you forgot to create this file. When creating a new Apex Class in VS Code, you should use the SFDX: Create Apex Class command option (right-click on the
classes
folder to find this menu item), instead of manually creating the file.