FOR REFERENCE:
FOR REFERENCE clause to notify Salesforce when a record is referenced from a custom interface, such as in a mobile application or from a custom page. A record is referenced every time a related record is viewed. For example, when a user views an account record, all related records (such as contacts, owner, leads, opportunities) are referenced.
Example:
This SOQL query that retrieves a contact and uses FOR REFERENCE to update the Last Referenced Date field of the retrieved contact.
SELECT Name, ID FROM Contact LIMIT 1 FOR REFERENCE
Before Using FOR VIEW go through this points:
1. The LastReferencedDate field is updated for any retrieved records.
2. A record is added to the RecentlyViewed object to reflect the recently referenced data for each retrieved record.
3. Use this clause only when you’re certain that the records affected by the query will be referenced, else the clause falsely updates the recently referenced information for any retrieved 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.
1. The LastReferencedDate field is updated for any retrieved records.
2. A record is added to the RecentlyViewed object to reflect the recently referenced data for each retrieved record.
3. Use this clause only when you’re certain that the records affected by the query will be referenced, else the clause falsely updates the recently referenced information for any retrieved 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.