How to delete test code coverage data?

189 views
Skip to first unread message

dougla...@gmail.com

unread,
Aug 30, 2017, 6:58:17 PM8/30/17
to Illuminated Cloud Q&A
Is there a way in IC to delete test code coverage data?

Currently I use Developer Console > Test > Clear Test Data to do it.



Poking around the Tooling API, I discovered objects named ApexOrgWideCoverage and ApexCodeCoverage.


After performing a tooling soql query on each object to determine the records that exists then I was able to delete them. That effectively wiped out test code coverage.


GET /services/data/v40.0/tooling/query?q=SELECT+id+FROM+ApexOrgWideCoverage

DELETE /services/data/v40.0/tooling/sobjects/ApexOrgWideCoverage/{id}


GET /services/data/v40.0/tooling/query?q=SELECT+id+FROM+ApexCodeCoverage

DELETE /services/data/v40.0/tooling/sobjects/ApexCodeCoverage/{id}


Probably using the /composite endpoing could help chunk delete up to 25 code coverage records at a time.


Dunno... looking for something that doesn't require me to open dev console, but to code something up in IC seems way too much effort unless you know better option?


Thanks!


Doug




Scott

unread,
Aug 30, 2017, 7:01:47 PM8/30/17
to Illuminated Cloud Q&A
Doug, I'll have to search some old emails, but I think I tried to integrate this a bit back and there was no published API to do so.  Whatever Dev Console is doing seems to be undocumented.  I looked at deleting the Tooling API objects but was nervous it might leave the system in an inconsistent state since that info is available through other APIs as well.  One would think it would converge on the same backing store, but I just didn't like the idea of doing something that could brick an org like that.

If anyone does know a sanctioned way to do this, please let me know and I'll be happy to integrate it.

Regards,
Scott

dougla...@gmail.com

unread,
Jul 9, 2019, 10:43:37 PM7/9/19
to Illuminated Cloud Q&A
Hi Scott,

As a follow up to this conversation, I found these two help articles that discuss deleting records from ApexCodeCoverage and ApexCodeCoverageAggregate via Tooling API to clear code coverage metrics. As this is documented for customers to do, this seems safe enough to do.



I've not needed to do this recently, I was just reviewing these forums and wanted to follow up with documentation as in your last response that you were "nervous it might leave the system in an inconsistent state". I don't think it does as I've done this multiple times myself and it's documented in the help articles.

Thanks,

Doug

Scott

unread,
Jul 9, 2019, 10:52:30 PM7/9/19
to Illuminated Cloud Q&A
Thanks for the info, Doug. The JetBrains plugin SDK evidently now supports hits-per-line code coverage (i.e., linking to all tests that drove coverage of product code) and I was going to look at integrating it soon. I'll keep this around for when I do so since it's in the same general area.

Regards,
Scott

Reply all
Reply to author
Forward
0 new messages