Newer Version Available
FOR VIEW
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.
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.
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