Salesforce stores information
about record views in the interface and uses the information to generate a list of recently viewed
and referenced records, such as a list of records in a sidebar and for a list of records as
auto-complete options in search. You can update objects with information about when they were last
viewed by using the FOR VIEW clause in a SOQL query.
Salesforce stores information about
record views in the interface and uses it to generate a list of recently viewed and referenced
records, such as in the sidebar and for the auto-complete options in search. You can use the
FOR VIEW clause to notify Salesforce when a record is viewed from a custom
interface, such as in a mobile application or from a custom page, so that the recently viewed
data is always current. Consider using the FOR VIEW clause in conjunction
with the FOR REFERENCE
clause to update recent usage data for retrieved objects.
When this clause is used with a query, two things happen:
- The LastViewedDate field for the retrieved record is updated.
- A record is added to the RecentlyViewed object to reflect the recently viewed data for the
retrieved record.
- Use this clause only when you are sure that the retrieved records will definitely be viewed
by the logged-in user, else the clause falsely updates the usage information for the records.
Also, the user won’t recognize any falsely updated records when they display in the
Recent Items and the global search auto-complete lists.
- The RecentlyViewed object is updated every time the logged-in user views or references a record. It is also
updated when records are retrieved using the FOR VIEW or
FOR REFERENCE clause in a SOQL query. To ensure that the
most recent data is available, RecentlyViewed data is periodically truncated down to 200 records per object.
This is an example of a SOQL query
that retrieves one contact to show to the current user and uses FOR
VIEW to update the last viewed date of the retrieved contact. The same statement both
retrieves the record and updates its last viewed date.
1SELECT Name, ID FROM Contact LIMIT 1 FOR VIEW