Skip to content

forcedotcom/sf-skills / plugins/builder/experience-react/skills/experience-ui-bundle-salesforce-data-access

experience-ui-bundle-salesforce-data-access

Verified

MUST activate whenever a uiBundles/*/src/ project reads, writes, or displays Salesforce data — INCLUDING building a page, list, table, card grid, dashboard, or form that shows, filters, counts, or edits records of any object (e.g. Property__c, Account, Case), even when the prompt names only the UI or the object and never says query, GraphQL, or SDK. Records behind such a component come from Salesforce, so use this ALONGSIDE experience-ui-bundle-frontend-generate: that skill styles the component, this one wires its data. Also triggers on @salesforce/platform-sdk imports, sdk.graphql.query / mutate / sdk.fetch calls, *.graphql files, or stale data needing force-refresh. New read/write work uses the current @salesforce/platform-sdk API; migrate only EXISTING old @salesforce/sdk-data callable code. Not for pure styling/layout with no records, app shell, file upload, or auth/search scaffolding. DO NOT TRIGGER for OAuth, object/field schema changes, Bulk/Tooling/Metadata API, or declarative automation.

FileKindSize
SKILL.mdskill md29.6 KB
references/caching.mdmarkdown8.8 KB
references/graphiti-cli.mdmarkdown19.5 KB
references/graphql-hand-authoring.mdmarkdown14.9 KB
references/migration.mdmarkdown6.0 KB
references/rest-and-integration.mdmarkdown6.7 KB
references/sdk-api.mdmarkdown4.9 KB
scripts/graphql-search.shexecutablescript7.6 KB

references/rest-and-integration.md

View on GitHub
# REST (`sdk.fetch`) & UI bundle integration

Use `sdk.fetch` only when GraphQL doesn't cover the use case. The allowlist is in
[SKILL.md](../SKILL.md#platform-guardrails--never-regress-these) (guardrail 9). Every code shape
here is grounded in shipped consumer code.

## Supported APIs (allowlist)

| API | Method | Endpoints / use case |
|---|---|---|
| GraphQL | `sdk.graphql` | all record queries/mutations via the `uiapi { }` namespace |
| UI API REST | `sdk.fetch` | `/services/data/v{ver}/ui-api/records/{id}` — record metadata when GraphQL insufficient |
| Apex REST | `sdk.fetch` | `/services/apexrest/{resource}` — custom server logic, aggregates, multi-step transactions |
| Connect REST | `sdk.fetch` | `/services/data/v{ver}/connect/file/upload/config` — file upload config |
| Einstein LLM | `sdk.fetch` | `/services/data/v{ver}/einstein/llm/prompt/generations` — AI text generation |

**Not supported:** Enterprise REST query (`/services/data/v*/query` with SOQL — blocked at the
proxy; use GraphQL for reads, Apex REST for server-side SOQL aggregates), Aura-enabled Apex
(`@AuraEnabled` — no invocation path from UI bundles), Chatter API (`/chatter/users/me` — use
`uiapi { currentUser { ... } }`), and any other Salesforce REST endpoint not in the table above.

> `sdk.fetch` is **not cached** — only `sdk.graphql!.query()` participates in the resource
> cache. REST reads hit the network every time.

## `sdk.fetch` patterns

```typescript
declare const __SF_API_VERSION__: string;
const API_VERSION = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";

// Connect — file upload config
const res = await sdk.fetch!(`/services/data/v${API_VERSION}/connect/file/upload/config`);

// Apex REST (no version in path)
const res = await sdk.fetch!("/services/apexrest/auth/login", {
  method: "POST",
  body: JSON.stringify({ email, password }),
  headers: { "Content-Type": "application/json" },
});

// UI API — record with metadata (prefer GraphQL for simple reads)
const res = await sdk.fetch!(`/services/data/v${API_VERSION}/ui-api/records/${recordId}`);

// Einstein LLM
const res = await sdk.fetch!(`/services/data/v${API_VERSION}/einstein/llm/prompt/generations`, {
  method: "POST",
  body: JSON.stringify({ promptTextOrId: prompt }),
});
```

Use `sdk.fetch!` (non-null assertion) just as `sdk.graphql!` — `fetch` is also optional on
`DataSDK`. When you call `sdk.fetch` you are handling raw HTTP, so check `response.ok` and then
parse the JSON body's `errors` array yourself (HTTP 200 still doesn't guarantee a successful
GraphQL/REST body):

```typescript
const response = await sdk.fetch!(url, { method: "GET", headers: { Accept: "application/json" } });
if (!response.ok) throw new Error(`Request failed: ${response.statusText}`);
const result = (await response.json()) as { data?: unknown; errors?: { message: string }[] };
if (result.errors?.length) throw new Error(result.errors.map((e) => e.message).join("; "));
```

> **Advanced / escape hatch — GraphQL over GET.** The supported path for record reads is
> `sdk.graphql!.query()` (POST, cached, typed) — see guardrail 9 in
> [SKILL.md](../SKILL.md#platform-guardrails--never-regress-these), which lists GraphQL as
> supported *only* via `sdk.graphql`. The shipped `accounts.ts` *demonstrates* issuing GraphQL
> as a `GET` through `sdk.fetch` — encoding the operation as a `queryInput` URL param against
> `/services/data/v{ver}/graphql` — but this is an example-app demonstration, not a sanctioned
> platform pattern. It sits below the supported-API contract: it bypasses the resource cache,
> the generated-type plumbing, and the supported-surface guarantee. Do not reach for it for
> ordinary record reads; stay on `sdk.graphql!.query()`.

## UI bundle integration (reactive / lifecycle code)

The patterns below are framework-agnostic — the SDK calls are plain `async`; only *where* you
place them (a React effect, a Vue/Svelte lifecycle hook, a web-component `connectedCallback`,
a store action) varies by UI layer.

### Pattern 1 — external `.graphql` file (complex queries)

**One operation per `.graphql` file** (one `query` or `mutation` plus its fragments). Import with
the `?raw` suffix; pass the imported string as `query`.

```typescript
import { createDataSDK, type NodeOfConnection } from "@salesforce/platform-sdk";
import MY_QUERY from "./query/myQuery.graphql?raw"; // ?raw suffix required
import type { GetMyDataQuery, GetMyDataQueryVariables } from "../graphql-operations-types";

const sdk = await createDataSDK();
const result = await sdk.graphql!.query<GetMyDataQuery, GetMyDataQueryVariables>({
  query: MY_QUERY,
  variables,
});
```

Run `npm run graphql:codegen` after creating/changing `.graphql` files.

### Pattern 2 — inline `gql` tag (simple queries)

**Must use `gql`** — plain template strings bypass ESLint schema validation. This is exactly the
shape of the shipped `accounts.ts`.

```typescript
import { createDataSDK, gql } from "@salesforce/platform-sdk";
import type { GetAccountsQuery, GetAccountsQueryVariables } from "../graphql-operations-types";

const GET_ACCOUNTS = gql`
  query GetAccounts($first: Int, $after: String) {
    uiapi { query {
      Account(first: $first, after: $after, orderBy: { Name: { order: ASC } }) {
        edges { node { Id Name @optional { value } Industry @optional { value } } }
        pageInfo { hasNextPage endCursor }
      }
    } }
  }
`;

const sdk = await createDataSDK();
const result = await sdk.graphql!.query<GetAccountsQuery, GetAccountsQueryVariables>({
  query: GET_ACCOUNTS,
  variables: { first: 20 },
});
```

### Canonical thin client (the scaffold)

The base-react-app template ships a thin wrapper (`graphqlClient.ts`) that every new app starts
from. Reuse it rather than re-implementing error handling:

```typescript
import { createDataSDK } from "@salesforce/platform-sdk";

export async function executeGraphQL<TData, TVariables>(
  query: string,
  variables?: TVariables,
): Promise<TData> {
  const sdk = await createDataSDK();
  const result = await sdk.graphql!.query<TData, TVariables>({ query, variables });
  if (result.errors?.length) {
    throw new Error(`GraphQL Error: ${result.errors.map((e) => e.message).join("; ")}`);
  }
  if (result.data == null) throw new Error("GraphQL response data is null");
  return result.data;
}
```

(To thread caching or use the reactive handle, call `sdk.graphql!.query()` directly with
`cacheControl` / `subscribe` — see [SKILL.md → Freshness & caching](../SKILL.md#freshness--caching),
which grounds on **tier-2b** `docs/data/`.)

> Directory layout and the full command table (`graphql:schema` / `graphql:codegen` / `eslint` /
> `graphql-search.sh`, plus the graphiti commands) live in the spine — see
> [SKILL.md](../SKILL.md#commands--layout).
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall