FOR VIEW:
FOR VIEW clause 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 Recently Items and for the auto-complete options in search. You can update objects with information about when they were last viewed using the FOR VIEW clause.
recently viewed and referenced records, such as in the sidebar Recently Items and for the auto-complete options in search. You can update objects with information about when they were last viewed using the FOR VIEW clause.
Example:
Thsi SOQL query that retrieves one Account to show to the current user and uses FOR VIEW to update the last viewed date of the retrieved Account. The same statement both retrieves the record and updates its last viewed date.
SELECT Name, ID FROM Account LIMIT 1 FOR VIEW
Before Using FOR VIEW go through this points:
1. The LastViewedDate field for the retrieved record is updated.
2. A record is added to the RecentlyViewed object to reflect the recently viewed data for the retrieved record.
1. The LastViewedDate field for the retrieved record is updated.
2. A record is added to the RecentlyViewed object to reflect the recently viewed data for the retrieved record.
3. 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.
4. 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.
4. 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.