0

Whenever I try to delete apex classes from production, I receive the following errors during the validation of all tests in the org on two unrelated test classes, and the entire delete transaction fails:

System.QueryException: sObject type 'RecentlyViewed' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

The thing is, the ReventlyViewed is the standard Salesforce object that has been around for years, and the two test classes are on API v44.0. The test methods pass successfully during a deployment of new classes or updates to existing classes - I only see this error when trying to delete Apex Classes. Has anyone seen this issue or resolved it?

  • 1
    The test classes may be referencing other classes that do the SOQL and such classes are below V44 – cropredy Feb 13 at 22:59
1

As stated in Known Issue: Apex test fails by "System.QueryException: sObject type 'RecentlyViewed' is not supported. ..."[...] it's worth checking if there are no Classes/Triggers defined with API version lower than 28.0. It's usually a problem when it comes to this Exception to be thrown:

Summary

Apex test which uses RecentlyViewed fails by "System.QueryException: sObject type 'RecentlyViewed' is not supported. ..." when installed managed package has Apex trigger which API version is less than 28

Repro

Create a managed package with the below components:

Trigger: Version 27.0 or below:

trigger W2878927Trigger on Account (after insert) {
List<Account> accts = [select id from account limit 10];
}


@isTest
private class W2878927Test {
private static testmethod void doTest() {
Account acct = new Account(Name='TEST');
insert acct;
}
}

Install the managed package in any org and create a test class as:


@IsTest
public class W2878927
{
private static testMethod void test1() {
}

private static testMethod void test2()
{
List<RecentlyViewed> rvs=[select Id from RecentlyViewed where Type = 'User' order by LastViewedDate desc limit 10];
}
}

Do "Compile all classes" and then run the above test class.

You will see test2 method fails by the following error. System.QueryException: sObject type 'RecentlyViewed' is not supported. If you are attempting to use a custom object, be sure to append the '__c' after the entity name. Please reference your WSDL or the describe call for the appropriate names.

Workaround

Update the API version of Apex trigger in installed managed package to 28.0 or later to resolve the issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.