Friday, September 17, 2021

SFDX running apex scripts

This bash script will help you launch apex scripts.

To launch the scripts, is using the command:

sfdx force:apex:execute -u <alias> -f <script.apex> 

link: https://github.com/d2269/SFScripts/tree/main/bash/running_apex_scripts 

Script:

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




Friday, September 3, 2021

If you need to connect to the sandbox SFDX

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