RecentlyViewed

Represents metadata entities typically found in Setup such as page layout definitions, workflow rule definitions, and email templates that the current user has recently viewed.

Version 

Introduced in API version 33.0.

Supported SOAP API Calls 

describeSObjects(), query(), update()

Supported REST API Methods 

PATCH, Query

Special Usage Rules 

The RecentlyViewed object supports the following metadata entities:

  • Apex classes
  • Apex triggers
  • Approval processes
  • Apps
  • Custom report types
  • Email templates
  • Fields
  • Objects
  • Page layouts
  • Permission sets
  • Profiles
  • Static resources
  • Tabs
  • Users
  • Validation rules
  • Visualforce pages
  • Visualforce components
  • Workflow email alerts
  • Workflow field updates
  • Workflow outbound messages
  • Workflow rules
  • Workflow tasks

Fields 

Alias 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The alias on the item.

Email 

  • Type: email

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The email address on the item.

FirstName 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The first name on the item.

IsActive 

  • Type: boolean

  • Required: No

  • Properties: Defaulted on create, Filter, Group, Sort

  • Description: Indicates whether the recently viewed item is an active user (true) or not (false). This field contains a value only if the recently viewed item is a user.

  • Default value: false

Language 

  • Type: picklist

  • Required: No

  • Properties: Group, Nillable, Restricted picklist, Sort

  • Introduced: API version 30.0

  • Description: The language of the Recently Viewed.

  • Possible values:

    • en_US — English

    • de — German

    • es — Spanish

    • fr — French

    • it — Italian

    • ja — Japanese

    • sv — Swedish

    • ko — Korean

    • zh_TW — Chinese (Traditional)

    • zh_CN — Chinese (Simplified)

    • pt_BR — Portuguese (Brazil)

    • nl_NL — Dutch

    • da — Danish

    • th — Thai

    • fi — Finnish

    • ru — Russian

    • es_MX — Spanish (Mexico)

    • no — Norwegian

LastName 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The last name on the item.

MiddleName 

  • Type: string
  • Required: No
  • Properties: Filter, Group, Nillable, Sort

Name 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: If the recently viewed item is a user, this is the user’s name. Specifically, it’s the concatenation of the FirstName and LastName field values.

NameOrAlias 

  • Type: string
  • Required: No
  • Properties: Filter, Group, Nillable, Sort
  • Introduced: API version 39.0

NetworkId 

  • Type: ID

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Introduced: API version 27.0

  • Description: The ID of the Experience Cloud site that this recently viewed item is part of. This field is available only if digital experiences is enabled in your org.

Phone 

  • Type: phone

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The phone number on the item.

ProfileId 

  • Type: reference

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: If the recently viewed item is a user, this is the user’s profile ID.

  • Relationship name: Profile

  • Relationship type: relationship

  • Refers to: Profile

RelatedObject 

  • Type: picklist

  • Required: No

  • Properties: Filter, Group, Nillable, Restricted picklist, Sort

  • Introduced: API version 34.0

  • Description: The object that the recently viewed item is related to. For example, if the recently viewed item is an Account Custom Field, then the related object will be Account. Not all recently viewed items will have a related object.

Suffix 

  • Type: string
  • Required: No
  • Properties: Filter, Group, Nillable, Sort

Title 

  • Type: string

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: If the recently viewed item is a user, this is the user’s title. For example, CFO or CEO.

Type 

  • Type: picklist

  • Required: No

  • Properties: Filter, Group, Nillable, Restricted picklist, Sort

  • Description: The sObject type for this recently viewed item.

UserRoleId 

  • Type: reference

  • Required: No

  • Properties: Filter, Group, Nillable, Sort

  • Description: The ID of the user role associated with this object.

  • Relationship name: UserRole

  • Relationship type: relationship

  • Refers to: UserRole

Usage 

This object provides a heterogeneous list of different metadata types and consists of recently viewed records. A record is considered viewed when the user sees the details associated with it, but not when the user sees it in a list with other records. Use this object to programmatically construct a list of recently viewed items specific to the current user, for example, on a custom user interface or for search auto-complete options. You can also retrieve a filtered list of records by object type (Type). The RecentlyViewed data is periodically truncated down to 200 records per object. RecentlyViewed data is retained for 90 days, after which it is removed on a periodic basis.

Use this query in your code to retrieve a list of all the records that were recently viewed. The results are ordered from most to least recent.

1SELECT Id, Name
2FROM RecentlyViewed
3WHERE LastViewedDate !=null
4ORDER BY LastViewedDate DESC

Use this query to retrieve data that was either viewed or referenced, but only for a limited set of objects.

1SELECT Id, Name
2FROM RecentlyViewed 
3WHERE Type IN ('CustomEntityDefinition', 'CustomFieldDefinition')
4ORDER BY LastViewedDate DESC

DID THIS ARTICLE SOLVE YOUR ISSUE?
Let us know so we can improve!