I just created a new scratch org and then went to push the current metadata source to it with the command:
sfdx force:source:push
The failed with an error:
ERROR running force:source:push: Expected file at path: D:\p\force-app\main\default\classes\BatchClassThatDoesNotExist.cls-meta.xml
Which seemed odd, as there never was a BatchClassThatDoesNotExist
class in the project. Somehow there was a BatchClassThatDoesNotExist.cls in the file system (but no corresponding .cls-meta.xml). I chalked that up to some oddity that accidentally created a new file and just removed the offending file BatchClassThatDoesNotExist.cls.
Now when I attempt the same push operation to the scratch org I get the error:
ERROR running force:source:push: Expected file at path: D:\p\force-app\main\default\classes\BatchClassThatDoesNotExist.cls
Which seems odd, as I just intentionally deleted that file in VSCode.
How can I get the source pushing to the scratch org correctly without the unwanted class?
Best Answer
Beyond the problem of the rogue class file, I assume the problem is related to the local source tracking that the SFDX CLI performs. It still wants to push the file to Salesforce even though it no longer exists.
The following command will reset the local source tracking.
It does come with the following warning:
This should be fine for a scratch org that is otherwise empty.