I have some code that queries RecentlyViewed and needed to be unit tested. I noticed a failure today because more records are turning up than expected.

It turns out that if you query RecentlyViewed in a unit test, even without seeAllData, you still get actual records back. Should this be considered a bug in Apex?

  • I'll ask around. Give me a bit.
    – sfdcfox
    Apr 17 '18 at 23:06
  • Are the records indicated by the RecentlyViewed.Id field accessible in the test case? It's a bit of a special case as a "heterogeneous list of different object types" with a degree of background processing that prunes records out. Apr 17 '18 at 23:10
  • 1
    @DanielBallinger It should either be isolated, or mentioned in the docs as being non-isolated. Either way, I feel it's a documentation vs behavior issue.
    – sfdcfox
    Apr 17 '18 at 23:17
  • +1 I'm all for consistency and documentation of exceptional behavior. Apr 17 '18 at 23:19
  • 1
    I believe the records themselves don't show up if query directly from their object table, however I can find their name and ID in RecentlyViewed. So yeah this should be either documented or considered a defect. I'll log a case in the Partner portal.
    – Charles T
    Apr 18 '18 at 0:02

This has now been posted as a Known Issue. See here to click that it affects you:


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.