Kysoql
Salesforce-specific features

Scopes, visibility, and MRU tracking

Use root-query Salesforce clauses exposed by generated object capabilities.

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

USING SCOPE

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

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

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.

On this page