Tuesday, November 19, 2019

How to get recently viewed information of user in org using SOQL

Salesforce stores the recently viewed information in RecentlyViewed object
RecentlyViewed represents records that the current user has recently viewed or referenced (by viewing a related record).

If you want to query the multiple sObject records recently viewed information.
Ex: I want to see the recently viewed account and contact records in org.
Select Id, Name, Type, LastViewedDate, Profile.Name FROM RecentlyViewed WHERE Type IN ('Account', 'Contact') ORDER BY LastViewedDate DESC

You can also use the LastViewdDate field on the sObject. 
Ex: I want to see only recently viewed Account records.
SELECT Id, Name, LastViewedDate FROM Account WHERE LastViewedDate != NULL ORDER BY LastViewedDate DESC limit 5

RecentlyViewed Object

No comments:

Post a Comment