RecentlyViewed

Represents records that the current user has recently viewed or referenced (by viewing a related record).

Supported Calls

query(), update()update()

Special Usage Rules

The RecentlyViewed object does not support the Task, Report, KnowledgeArticle, and Article objects.

Fields

Field Details
Alias
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The alias on the record.
Email
Type
email
Properties
Filter, Group, Nillable, Sort
Description
The email address on the record.
FirstName
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The first name on the record. If the recently viewed record is a user, this is the user’s first name.
Id
Type
ID
Properties
Defaulted on create, Filter, Group, Sort
Description
The ID of the recently viewed record.
IsActive
Type
boolean
Properties
Defaulted on create, Filter, Group, Sort
Description
Indicates whether the recently viewed record is an active user (true) or not (false). This field contains a value only if the recently viewed record is a user.
LastName
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The last name on the record.
LastReferencedDate
Type
dateTime
Properties
Filter, Nillable, Sort, Update
Description
The timestamp for when the current user last viewed a record related to this record.
LastViewedDate
Type
dateTime
Properties
Filter, Nillable, Sort, Update
Description
The timestamp for when the current user last viewed this record. If this value is null, this record might only have been referenced (LastReferencedDate) and not viewed.
Name
Type
string
Properties
Filter, Group, Nillable, Sort
Description
The name on the recently viewed record. If the recently viewed record is a user, contact, or lead, the value is a concatenation of the firstname and lastname field values.
NetworkId
Type
reference
Properties
Filter,Group, Nillable, Sort
Description
ID of the community that this group is part of. This field is available only if Salesforce Communities is enabled in your organization.

You can add a NetworkId only when creating a group. You can’t change or add a NetworkId for an existing group. This field is available in API version 27.0 and later.

Phone
Type
phone
Properties
Filter, Group, Nillable, Sort
Description
The phone number on the record.
ProfileId
Type
reference
Properties
Filter, Group, Nillable, Sort
Description
If the recently viewed record is a user, this is the user’s profile ID.
Title
Type
string
Properties
Filter, Group, Nillable, Sort
Description
If the recently viewed record is a user, this is the title of the user; for example CFO or CEO.
Type
Type
picklist
Properties
Filter, Group, Nillable, Restricted, picklistSort
Description
The sObject type for this recently viewed record. Valid values include any standard or custom objects that RecentlyViewed supports.
UserRoleId
Type
reference
Properties
Filter, Group, Nillable, Sort
Description
The ID of the user role associated with this object.

Usage

This object provides a heterogeneous list of different object types and consists of recently viewed records or records that were recently referenced (a related record was viewed). 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.

SELECT Id, Name
FROM RecentlyViewed
WHERE LastViewedDate !=null
ORDER BY LastViewedDate DESC 

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

SELECT Id, Name
FROM RecentlyViewed 
WHERE Type IN ('Account', 'Contact', 'Plan__c')
ORDER BY LastViewedDate DESC 

This query retrieves a list of all recently viewed contacts with contact-specific fields, such as the contact’s account name, and the custom website field. Records are ordered from most to least recent.

SELECT Account.Name, Title, Email, Phone, Website__c
FROM Contact
WHERE LastViewedDate != NULL 
ORDER BY LastViewedDate DESC