Newer Version Available

This content describes an older version of this product. View Latest

FOR REFERENCE

Use the 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. Consider using the FOR REFERENCE clause in conjunction with the FOR VIEW clause to update recent usage data for retrieved objects.

When this clause is used with a query, two things happen:
  • The LastReferencedDate field is updated for any retrieved records.
  • A record is added to the RecentlyViewed object to reflect the recently referenced data for each retrieved record.
  • 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. 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.

Note

This is an example of a SOQL query that retrieves a contact and uses FOR REFERENCE to update the LastReferencedDate field of the retrieved contact.

1SELECT Name, ID FROM Contact  LIMIT 1 FOR REFERENCE