# How does the FOR VIEW and FOR REFERENCE clause work in SOQL?

**Topic:** Soql · **Difficulty:** Medium · **Asked at:** Infosys, Persistent, EY · **Tags:** soql, keywords

Read it on the site: https://www.forcechallenges.com/interview-questions/how-does-the-for-view-and-for-reference-clause-work-in-soql

## Answer

`FOR VIEW` updates the `LastViewedDate` of the returned records so they show up in the user's **Recently Viewed** list. `FOR REFERENCE` updates `LastReferencedDate` (the record was referenced, e.g. in a lookup, without being viewed).

They are used to track usage so records appear in recent items and lookups.

```soql
SELECT Id, Name FROM Account WHERE Id = :accId FOR VIEW
```
The data lives on the `RecentlyViewed` object (`LastViewedDate`, `LastReferencedDate`).

---
Source: ForceChallenges · last updated 2026-10-21
