+ Start a Discussion
StephenDicksonStephenDickson 

SFDX: Deploy Source to Org failed to run in VS Code

I have been trying to deploy apex classes to a Trailhead Playgound as well as a developer org, but I receive the error "SFDX: Deploy Source to Org failed to run" in VS Code. 

Did I miss something when I set-up VS Code?
  • Salesforce CLI is up to date
  • All extensions are up to date
  • The orgs in question have been authorized successfully
  • The CLI appears to be installed correctly (when I run "sfdx" in the Terminal, I receive the Salesforce CLI menu)

This is the Salesforce CLI output:
Starting SFDX: Deploy Source to Org
11:35:46.868 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal
11:35:48.630 sfdx force:source:deploy --sourcepath c:\Salesforce\VSCodeQuickStart\force-app --json --loglevel fatal ended with exit code 1

Any help would be much appreciated!
Khan AnasKhan Anas (Salesforce Developers) 
Hi Stephen,

Greetings to you!

The code might have some errors. You can try solving the errors, shown in the error log and then try pushing it again.

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
StephenDicksonStephenDickson
Hi Khan, thanks for your reply.  

Unfortunately, VS Code is not detecting any errors.  I simply copied the AccountController class from the Trailhead module (https://trailhead.salesforce.com/en/content/learn/projects/quickstart-vscode-salesforce) and changed the orgName in project-scratch-def.json to "Learning VS Code" as instructed by the Trailhead module.
Lionel Momeni NgaleuLionel Momeni Ngaleu

@StephenDickson,

Where you abale to solve this? I'm also stucked with the same error

Stephen Dickson 10Stephen Dickson 10
Hi Lionel, 

It's been so long that I can't remember.  I think it may have been due to the fact that I didn't have test coverage.  Does that make sense for your situation?

Peace,
Stephen
Madhu Sudhan Reddy 6Madhu Sudhan Reddy 6
@Lionel Momeni Ngaleu Is it resolved? I am also getting same error. SFDX: Deploy Source to Org failed to run in VS Code
J BengelJ Bengel
I've encountered the same or a similar issue when deploying to a sandbox. The Problems list shows no errors, until I attempt to deploy source to org. At that point, one or more erorrs appear on the Problems tab in VSCode, which is what's causing the failure to deploy. This is simlar to the angry red text that dispalys at the top of the edit window if you're editing a class in Setup. Except if it happens there, you can simply fix the errors and retry. Unfortunately, the corrections are also not detected within VS Code, so I still can't deploy.

The only workaround I have found is to close all edit windows, close the folder, reopen the folder, let it reconnect and reauthorize the org and (attempt to) deploy again. That (usually) works unless there's a further problem (possibly in a dependent class) that wasn't detected until the original error was resolved, but it's (a) a time consuming workaround since you have to wait for the org to reauthorize after reopneing the folder, and (b) a real PITA to have to shut everything down and start it up again to find out if you've sufficiently appeased the SFDX gods.

This appears to be a disconnect between VS Code and the Apex compiler which fails to recognize the problem in the first place. Simple syntax errors (missing semicolon, mistmatched brackets, etc) that can be detecetd by the linter are flagged and listed in Problems. But anything more subtle than that is missed until you deploy. As far as I know, I have all the latest SFDX and CLI patches, but to date none of them have resolved the issue.

 
Parikhit SarkarParikhit Sarkar
Make sure you have created a cls-meta.xml file for the apex class that you want to deploy. 
It should look like this :- 
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <status>Active</status>
</ApexClass>

 
Aneela OadAneela Oad

I was having same issue with completing this module (https://trailhead.salesforce.com/en/content/learn/projects/quickstart-vscode-salesforce),  I simply copied the AccountController class from the Trailhead module and changed the orgName in project-scratch-def.json to "Learning VS Code" as instructed by the Trailhead module. The error was due to I did not create apex class using command pallate ( ctrl+shift+p)

Joshua BambrickJoshua Bambrick
I ran into this error as well. In my situation I had just downloaded VS Code, installed the Salesforce extension, and the SFDX cli. I did not have any errors listed under the Problems tab. I was able to resolve the error using a combination of the above steps: recreate using cmd + shift + p and closing the editor windows. In the bottom right corner I had an update that needed to be applied. After restarting VS Code I was able to deploy changes without any errors. 
Anjum Tadmod 3Anjum Tadmod 3
I had the same issue while deploying the Lightning Message Channel from VS to my playground. I found that the syntax of the file name was incorrect. 

The syntax of the file name should be as: <messageChannelname>.messageChannel-meta.xml
What I was doing was: <messageChannelname>-meta.xml
Once I corrected it the issue was solved. 

Hope this helps you 😊
Mike P 10897Mike P 10897
Seems like most of the answers have the commonality of an issue with the .xml file. I'm guessing there's not much, if any, error checking going on there within Visual Studio.

My issue was that I had renamed the object I was working with. I had updated all of my other files to replace the references to the old object name, but forgot to update the .xml file.
Nathanael Arinanja RandrianjanakaNathanael Arinanja Randrianjanaka
I do have the same problem: i just says "SFDX: Deploy Source to Org failed to run" without any further explanation! The only thing you see in th eTerminal is "Deploy Errors: 14:22:23.727 ended SFDX: Deploy Source to Org! I've already used the 52.0 as the API versoin, and then 54.0 but still nothing has changed! I'm actually on the Deploy Lightning Web Component files trailhead (not in the challenge yet)!
b1aNK_b1aNK_
OK so was facing similiar issue:
Resolved steps:
1. Reconnect VS code with your sandbox or ORG
2. Maybe your line of counts has been exceeded for that particular file try decreasing some lines .
Pankaj PandaoPankaj Pandao
Here is what I did :-
- I had "Salesforce Exetension Pack".
- I added the "Salesforce Exetension Pack (Extended)"
- Then Deployed the bikeCard Component, It worked.
Andre Baxter 21Andre Baxter 21
Try going to Set Up > Deployment Status.  From there you'll see more detailed errors about why your deployment is failing.  
Saddam Hussain 85Saddam Hussain 85
Put target tag into the meta file.
<targets>
        <target>lightning__AppPage</target>
        <target>lightning__HomePage</target>
</targets>
This has worked for me. Hopefully it will work for you.