0

I'm writing an Apex trigger and testing it against a Salesforce developer instance. I've been writing the code in VS Code, and deploying by running sf deploy.

When I run sf deploy the Test results summary tells me that all the tests are passing, but that the deployer "Salesforce Apps" exited with code 1.

I then visit "Setup > Platform Tools > Environments > Deploy > Deployment Status" and can see that the deployment failed because code coverage is only at 68%. But I can't find out where to see the detailed code-coverage report, either in VScode, through the Salesforce CLI or in the web interface.

Things I've tried without success include:

  • Running sfdx force:apex:test:run –-code-coverage –-result-format human - it says this comment is deprecated in favour of apex run test.
  • Looking in "Setup > Platform Tools > Custom Code > Apex Test Execution" - this only shows the available classes from the last time the deploy was successful, so doesn't include code I've added since then.
  • Running sf apex run test --code-coverage - this also only contains code from the last successful deploy, rather than the most recent code. This is true whatever value I use the --test-level option.

I think I might be missing something in my setup, but I can't work out what it is.

1 Answer 1

0

I've managed to solve this, by using a SFDX command through VS Code. I solved it by opening each of the Apex Classes and tests in VSCode, using the command pallette (Crtl+Shift+P) and choosing "SFDX: Deploy This Source to Org". This deployed each individual file to the Salesforce Org - they then appear in "Setup > Platform Tools > Custom Code > Apex Classes".

I was then able to run the tests through the web interface, which indicated where the issue was - an old Apex class which i'd deleted from my local copy was still deployed, and therefore didn't have any test coverage. After deleting this old class the test coverage went to 100%.

So I think the root cause was my misunderstanding of how Salesforce handles the deployed code, although I think the documentation & tooling could be clearer.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .