Skip to main content
40 votes
Accepted

How do I get Apex code coverage statistics when using Salesforce DX & Visual Studio Code

The easiest way to be able to view test coverage is to have set the --codecoverage flag (-c for short) to retrieve code coverage when you run the test command. > sfdx force:apex:test:run -c -u ...
pchittum's user avatar
  • 19.7k
26 votes
Accepted

How to run Apex anonymous code from Visual Studio Code

In the command palette, if you type "sfdx ex" you will be offered this if you have some Apex text selected: SFDX: Execute Anonymous Apex with Currently Selected Text or this: SFDX: Execute ...
Keith C's user avatar
  • 136k
18 votes
Accepted

Visual Studio Code download existing code

Another option is to use the SFDX: Create Project With Manifest command in VS Code (equivalent to using sfdx force:project:create with the -x or --manifest option), which will create your project with ...
Thomas Taylor's user avatar
16 votes

Format APEX code Visual Studio code

You can use uncrustify with VS Code. You need to install the code on your platform (http://uncrustify.sourceforge.net/), and then search for "uncrustify" in VS Code Extensions. Next, be sure to add ...
Vernon Keenan's user avatar
16 votes

Lightning Web Component: A required metadata folder named "lwc" does not exist in this workspace

For now, you need to have the pre-release version installed for DX: sfdx plugins:install salesforcedx@pre-release Make sure you've also updated all extensions, including Lightning Web Components, ...
sfdcfox's user avatar
  • 495k
15 votes

Trailhead Dreamhouse: ERROR running force:source:deploy: No source backed components present in the package

I had this issue, it was caused by my having the file type in my .forceignore Worth adding to to your list of things to check.
Jeremy Bowden's user avatar
14 votes

Visual Studio Code download existing code

You don't need --sourcepath. It looks at where you are pointing and tries to pull items which match what you have there already. What you do need is a package.xml file to get your entire metadata ...
Vernon Keenan's user avatar
13 votes
Accepted

How can I replace Mavensmate and Sublime Text with something supported?

I use these three: SFDX, the Force CLI and ForceCode (a VS Code Plugin). SFDX can be used to work with Sandbox, Production, and Scratch Orgs. The Force CLI is a grandparent of the sfdx plugin. ...
Christian Szandor Knapp's user avatar
13 votes

Can Visual Studio Code be used as an editor for Salesforce without SalesforceDX?

Looks like there is a better way now: Org Development Model with VS Code This link provides detailed instructions for using the "SFDX: Create Project with Manifest" command which enables connection ...
Mike Paisner's user avatar
12 votes

Format APEX code Visual Studio code

To make this easier, I have documented the Uncrustify steps that got this working for me on Mac OSX with VSCode: Install Uncrustify binaries with brew: > brew install uncrustify In VSCode, go to ...
Shanerk's user avatar
  • 1,076
11 votes

Format APEX code Visual Studio code

I assume that OP means the part of VS Code that determines standard formatting for Apex files. If you have Salesforce Extensions installed, typing SHIFT+ALT+F will give an error message: There is ...
frackham's user avatar
  • 431
11 votes

Apex PMD: Problem: Validate CRUD permission before SOQL/DML operation

PMD will not throw error if you follow the below syntax:- List<Contact> contacts = new List<Contact>(); // You add some code to populate the contacts name and phone. Before ...
Rahul Malhotra's user avatar
11 votes
Accepted

No sfdx-project.json found in the root directory of your open project. Open a Salesforce DX project in VS Code

You're missing a configuration file for some reason. Try the following. Close all files and folders in Visual Studio Code, then close it entirely. Create a new folder in your project directory ...
sfdcfox's user avatar
  • 495k
11 votes
Accepted

Lightning Web Component -- Lightning bundles must have a parent folder named ! 'lightningcomponents'

Lets understand how the vscode extension for lwc works . Vscode extension invokes the CLI commands that the salesforcedx cli plugin provides . In pilot release lwc folder was named as ...
Mohith Shrivastava's user avatar
11 votes

Reason: invalid_grant - expired access/refresh token

If reauthorizing doesn't help for some reasons(as I was facing) try deleting the alias as follows. It should definitely work Step 1. Go to /home/.sfdx (In windows c:\user\.sfdx) Step 2. Delete org ...
Arindam's user avatar
  • 173
10 votes
Accepted

Format APEX code Visual Studio code

Personally, I use the following extensions for vscode: Salesforce Extensions for VS Code - A package of Salesforce made extensions for editing code. Provides syntax highlighting & will recognize ...
battery.cord's user avatar
  • 8,835
10 votes
Accepted

Can Visual Studio Code be used as an editor for Salesforce without SalesforceDX?

There are some VisualStudio code extensions that can work without needing SFDX workflow. Note that current official plugin also supports working without DX scratch org support. I created my own ...
Mohith Shrivastava's user avatar
10 votes

How to run Apex anonymous code from Visual Studio Code

For all those command liners, you can also use force:apex:execute sfdx force:apex:execute -u MyConnectedOrg Start typing straight into the terminal or copy/paste your code of interest. Ctrl+D will ...
Brian Miller's user avatar
  • 5,222
10 votes
Accepted

VSCODE: Unable to Authorize to an ORG

There is a current regression bug in the Salesforce CLI latest version causing the issue. For now, you can work around by running below in your vscode terminal sfdx auth:web:login --setalias DevOrg --...
Mohith Shrivastava's user avatar
9 votes

Retrieving Custom Object using Visual Studio Code and Salesforce CLI

The easiest way I’ve found to do this is: sfdx force:source:retrieve -m CustomObject If you need it, include the -u option with your target username. This command pulls down all metadata of the type ...
Allison Letts's user avatar
8 votes
Accepted

Apex PMD: Problem: Validate CRUD permission before SOQL/DML operation

PMD's Apex ruleset is checking to see that you are enforcing/respecting security in your code. ISV's Managed packages released to the AppExchange must do this as mandatory criteria in the security ...
Mark Pond's user avatar
  • 23k
8 votes
Accepted

VS Code: "Unexpected end of JSON input" error when changing the default org

When checking the JSON files for the authorised orgs (on MacOS, this is in the ~/.sfdx directory), I noticed one of them was zero bytes. When that was deleted, everything was back working as normal.
Will's user avatar
  • 479
7 votes

Apex PMD: Problem: Validate CRUD permission before SOQL/DML operation

removing that kind of rule is not the solution, find an appropriate solution for it, and make changes in your code. I think the below changes in your code might help. SObject.sObjectType.getDescribe()....
Kishankumar Vasoya's user avatar
7 votes

Visual Studio Setup with Salesforce CLI for M1 Mac

The error message you got is helpful here, and tells you what to do. There was recently (October 22, 2020, CLI 7.77.1+, according to the release notes) a change made to the CLI to reorganize some ...
Derek F's user avatar
  • 62.5k
7 votes
Accepted

Error: INVALID_SESSION_ID: Session expired or invalid when Deploy on Visual Studio Code

I ran into this issue after I had to change my password in the sandbox. I just ran this command to fix it: sfdx force:auth:web:login -a <alias> -d -r https://test.salesforce.com This will open ...
dazmae's user avatar
  • 166
6 votes
Accepted

Getting error while retrieving Source from Salesforce Org using VS Code and Salesforce Extension Pack

The problem is that your sfdx-project.json file isn't a source file that can be retrieved. You'll need to select something valid to retrieve. This can be a particular metadata file (e.g., a specific ...
John Towers's user avatar
  • 3,873
6 votes

Reason: invalid_grant - expired access/refresh token

The easiest way to refresh the access token is just to open the scratch org via Salesforce DX. From the command palette, you can do > SFDX: Open Default Org. Or, from the integrated terminal, do ...
David Reed's user avatar
  • 93.2k
6 votes

Reason: invalid_grant - expired access/refresh token

These steps in Visual Studio Code will fix the issue, Step1: In the command palette SFDX: Authorize an Org Step2: Enter alias name (example: lwc_sandbox) Step3: Login into your Org from the default ...
shyam's user avatar
  • 161
6 votes

No code coverage information was found for test run 7070U00000r8Ny3. Set "salesforcedx-vscode-core.retrieve-test-code-coverage": true

I was having a similar issue. I'd added "salesforcedx-vscode-core.retrieve-test-code-coverage": true into the user "settings.json" as instructed. Yet the error message about "No code coverage ...
Daniel Ballinger's user avatar
6 votes

When to use 'Set a Default org' option in VS Code Salesforce

Yes, the org you specify with "Set a Default Org" is the one SDFX (and therefore VS Code) connects to by default for the purposes of metadata deployment, retrieval, test runs, etc. When you ...
Matthew Souther's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible