Fixed – “Compile Error: Type is not visible: test”

“Error: Compile Error: Type is not visible: test at line…” was bugging one of my peer developer for a while. For us, it was coming at a line in the source code where Test.startTest() call is made, though it can come at any other use of any method from the “Test” class.

At first, we thought that the API version of the class was not the latest, but then we recalled that it was not Test.isRunningTest(), but Test.startTest() that has been failing, which has existed for the last 3+ years. Then what could be the problem?

The problem came because some developer created an apex class named “Test.cls”, it’s unfortunate that this is allowed, but it is. This messed up the Apex runtime, and on some occasions, it worked but failed in most of the places where we are referring to the SYSTEM Test class.

We learned this lesson the hard way by wasting a lot of time. Posting this to save time for other developers who will Google for this strange issue.

Abhinav Gupta

First Indian Salesforce MVP, rewarded Eight times in a row, has been blogging about Salesforce, Cloud, AI, & Web3 since 2011. Founded 1st Salesforce Dreamin event in India, called “Jaipur Dev Fest”. A seasoned speaker at Dreamforce, Dreamin events, & local meets. Author of many popular GitHub repos featured in official Salesforce blogs, newsletters, and books.

https://abhinav.fyi
Previous
Previous

Fighting and Fixing the “MIXED_DML_OPERATION” Error!

Next
Next

Tip: Using Decimal class with Strings in Apex