Apex test fails by "System.QueryException: sObject type 'RecentlyViewed' is not supported. ..." when installed managed package has Apex trigger which
Last updated 2019-05-24 ·Reference W-2885465 ·Reported By 12 users
No Fix
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.
Is it Fixed?
Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.