Friday, September 10, 2021

Get test coverage from sandbox

Often, for a correct deployment, we need to know the test coverage of the apex code.
This is especially true for deployment using RunSpecifiedTests.
To do this, you can use the salesforce developer console.




But in order to give it to programmers to work, you need to get the test coverage of classes.

The SOQL query will help you with this:

To get the test coverage of classes and triggers, use 2 commands

1st (you will only get the aggregate coverage)
SOQL (with tooling API)

select ApexClassOrTrigger.Name, NumLinesUncovered, NumLinesCovered FROM ApexCodeCoverageAggregate

 
sfdx force:data:soql:query --query "select ApexClassOrTrigger.Name, NumLinesUncovered, NumLinesCovered FROM ApexCodeCoverageAggregate" --targetusername <alias> --usetoolingapi --resultformat csv > classes.csv

 
2nd (you will get the value of how many rows each method of each test class covers)
SOQL (with tooling API)

select ApexTestClass.Name, TestMethodName, ApexClassOrTrigger.Name, NumLinesUncovered, NumLinesCovered FROM ApexCodeCoverage

 
sfdx force:data:soql:query --query "select ApexTestClass.Name, TestMethodName, ApexClassOrTrigger.Name, NumLinesUncovered, NumLinesCovered FROM ApexCodeCoverage" --targetusername <alias> --usetoolingapi --resultformat csv > classesAandMethods.csv




1 comment:

  1. I prefer high-quality content, which I discovered in your article. The information you've provided is useful and important to us. Continue to post articles like these Expert Devops Services. Thank you very much.

    ReplyDelete

If you need to connect to the sandbox SFDX

 You can always view all possible connection methods in sfdx sfdx auth --help