# Scopes, visibility, and MRU tracking (/docs/core/advanced/scopes-and-visibility)



These methods apply to root queries and depend on generated object metadata.
They are intentionally absent from relationship subqueries.

## USING SCOPE [#using-scope]

```ts
import { db } from "./db";

const mine = db
  .selectFrom("Account")
  .select(["Id", "Name"])
  .usingScope("mine")
  .where("Name", "like", "Acme%");
```

The accepted value comes from the selected object's generated
`supportedScopes`. Calling `usingScope()` again replaces the previous scope.

Salesforce does not allow a root `USING SCOPE` query to also select a
parent-to-child subquery. Kysoql catches that combination locally.

## RecordVisibilityContext [#recordvisibilitycontext]

```ts
import { db } from "./db";

const query = db
  .selectFrom("Account")
  .select(["Id", "Name"])
  .withRecordVisibilityContext({
    maxDescriptorPerRecord: 100,
    supportsDomains: true,
    supportsDelegates: false,
  });
```

Provide at least one supported option. Repeated calls replace the whole context.
This clause shares Salesforce's filtering `WITH` slot with data categories,
`UserId`, and Apex access modes, so those forms cannot be combined on one query.

## FOR VIEW and FOR REFERENCE [#for-view-and-for-reference]

```ts
import { db } from "./db";

const query = db
  .selectFrom("Account")
  .select(["Id", "Name"])
  .limit(20)
  .forView();
```

`forView()` and `forReference()` require generated MRU support. They update
Salesforce Most Recently Used tracking and can therefore have observable side
effects. Avoid adding them to background reads unless that behaviour is intended.

Knowledge article tracking uses separate `UPDATE` clauses. See
[Knowledge and feeds](/docs/core/advanced/knowledge-and-feeds).
