@salesforce/webapp-template-feature-react-global-search-experimental 1.112.2 → 1.112.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,6 @@
1
1
  ---
2
2
  name: deploying-to-salesforce
3
- description: Enforces the correct order for deploying metadata, assigning permission sets, and fetching GraphQL schema. Use for ANY deployment to a Salesforce org — webapps, LWC, Aura, Apex, metadata, schema fetch, or org sync. Codifies setup-cli.mjs.
4
- paths:
5
- - "**/*"
3
+ description: Enforces the correct order for deploying metadata, assigning permission sets, and fetching GraphQL schema. Use for ANY deployment to a Salesforce org — webapps, LWC, Aura, Apex, metadata, schema fetch, or org sync.
6
4
  ---
7
5
 
8
6
  # Deploying to Salesforce
@@ -1,10 +1,6 @@
1
1
  ---
2
2
  name: using-salesforce-data
3
- description: Salesforce data access for reads, mutations, and REST APIs. Use when the user wants to fetch, display, create, update, or delete Salesforce records; add data fetching to a component; query Accounts, Contacts, Opportunities, or custom objects; call Chatter, Connect, or Apex REST APIs; or integrate Salesforce data into a webapp.
4
- paths:
5
- - "**/*.ts"
6
- - "**/*.tsx"
7
- - "**/*.graphql"
3
+ description: Salesforce data access for reading, writing, and querying records via REST, GraphQL, Apex, or Platform SDK. Use when the user wants to fetch, search, filter, sort, display, create, update, delete, or attach files to Salesforce records (standard objects like Accounts, Contacts, Opportunities, Cases, Quotes, or any custom object) in a web app or UI component (React, Angular, Vue, etc.); call Chatter, Connect, or Apex REST APIs; or invoke AuraEnabled Apex methods from an external app. Does not apply to authentication/OAuth setup, schema changes (adding fields, relationships), Bulk/Tooling/Metadata API usage, declarative automation (Flows, Process Builder), general LWC/Apex coding guidance without a specific data operation, or Salesforce admin/configuration tasks.
8
4
  ---
9
5
 
10
6
  # Salesforce Data Access
@@ -16,7 +12,7 @@ Use this skill when the user wants to:
16
12
  - **Fetch or display Salesforce data** — Query records (Account, Contact, Opportunity, custom objects) to show in a component
17
13
  - **Create, update, or delete records** — Perform mutations on Salesforce data
18
14
  - **Add data fetching to a component** — Wire up a React component to Salesforce data
19
- - **Call REST APIs** — Use Chatter, Connect, Apex REST, or UI API endpoints
15
+ - **Call REST APIs** — Use Connect REST, Apex REST, or UI API endpoints
20
16
  - **Explore the org schema** — Discover available objects, fields, or relationships
21
17
 
22
18
  ## Data SDK Requirement
@@ -31,18 +27,38 @@ const sdk = await createDataSDK();
31
27
  // GraphQL for record queries/mutations (PREFERRED)
32
28
  const response = await sdk.graphql?.<ResponseType>(query, variables);
33
29
 
34
- // REST for Chatter, Connect, Apex REST (when GraphQL insufficient)
35
- const res = await sdk.fetch?.("/services/data/v65.0/chatter/users/me");
30
+ // REST for Connect REST, Apex REST, UI API (when GraphQL insufficient)
31
+ const res = await sdk.fetch?.("/services/apexrest/my-resource");
36
32
  ```
37
33
 
38
34
  **Always use optional chaining** (`sdk.graphql?.()`, `sdk.fetch?.()`) — these methods may be undefined in some surfaces.
39
35
 
36
+ ## Supported APIs
37
+
38
+ **Only the following APIs are permitted.** Any endpoint not listed here must not be used.
39
+
40
+ | API | Method | Endpoints / Use Case |
41
+ |-----|--------|----------------------|
42
+ | GraphQL | `sdk.graphql` | All record queries and mutations via `uiapi { }` namespace |
43
+ | UI API REST | `sdk.fetch` | `/services/data/v{ver}/ui-api/records/{id}` — record metadata when GraphQL is insufficient |
44
+ | Apex REST | `sdk.fetch` | `/services/apexrest/{resource}` — custom server-side logic, aggregates, multi-step transactions |
45
+ | Connect REST | `sdk.fetch` | `/services/data/v{ver}/connect/file/upload/config` — file upload config |
46
+ | Einstein LLM | `sdk.fetch` | `/services/data/v{ver}/einstein/llm/prompt/generations` — AI text generation |
47
+
48
+ **Not supported:**
49
+
50
+ - **Enterprise REST query endpoint** (`/services/data/v*/query` with SOQL) — blocked at the proxy level. Use GraphQL for record reads; use Apex REST if server-side SOQL aggregates are required.
51
+ - **Aura-enabled Apex** (`@AuraEnabled`) — an LWC/Aura pattern with no invocation path from React webapps.
52
+ - **Chatter API** (`/chatter/users/me`) — use `uiapi { currentUser { ... } }` in a GraphQL query instead.
53
+ - **Any other Salesforce REST endpoint** not listed in the supported table above.
54
+
40
55
  ## Decision: GraphQL vs REST
41
56
 
42
57
  | Need | Method | Example |
43
58
  |------|--------|---------|
44
59
  | Query/mutate records | `sdk.graphql` | Account, Contact, custom objects |
45
- | Chatter API | `sdk.fetch` | `/chatter/users/me` |
60
+ | Current user info | `sdk.graphql` | `uiapi { currentUser { Id Name { value } } }` |
61
+ | UI API record metadata | `sdk.fetch` | `/ui-api/records/{id}` |
46
62
  | Connect REST | `sdk.fetch` | `/connect/file/upload/config` |
47
63
  | Apex REST | `sdk.fetch` | `/services/apexrest/auth/login` |
48
64
  | Einstein LLM | `sdk.fetch` | `/einstein/llm/prompt/generations` |
@@ -55,32 +71,36 @@ const res = await sdk.fetch?.("/services/data/v65.0/chatter/users/me");
55
71
 
56
72
  ### Step 1: Acquire Schema
57
73
 
58
- The `schema.graphql` file (265K+ lines) is the source of truth. **Use grep only** — never open or parse the file directly.
74
+ The `schema.graphql` file (265K+ lines) is the source of truth. **Never open or parse it directly.**
59
75
 
60
76
  1. Check if `schema.graphql` exists at the SFDX project root
61
77
  2. If missing, run from the **webapp dir**: `npm run graphql:schema`
62
78
  3. Custom objects appear only after metadata is deployed
63
79
 
64
- ### Step 2: Identify & Introspect Entities
80
+ ### Step 2: Look Up Entity Schema
65
81
 
66
- Map user intent to PascalCase names ("accounts" → `Account`). Validate via grep:
82
+ Map user intent to PascalCase names ("accounts" → `Account`), then **run the search script from the project root**:
67
83
 
68
84
  ```bash
69
- # From project root — find entity fields
70
- grep -nE '^type Account implements Record' ./schema.graphql -A 100
85
+ # From project root — look up all relevant schema info for one or more entities
86
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account
71
87
 
72
- # Find filter options
73
- grep -nE '^input Account_Filter' ./schema.graphql -A 50
74
-
75
- # Find mutation input
76
- grep -nE '^input AccountCreateInput' ./schema.graphql -A 50
88
+ # Multiple entities at once
89
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account Contact Opportunity
77
90
  ```
78
91
 
79
- **Maximum 3 introspection cycles.** If entities remain unknown, ask the user.
92
+ The script outputs five sections per entity:
93
+ 1. **Type definition** — all queryable fields and relationships
94
+ 2. **Filter options** — available fields for `where:` conditions
95
+ 3. **Sort options** — available fields for `orderBy:`
96
+ 4. **Create input** — fields accepted by create mutations
97
+ 5. **Update input** — fields accepted by update mutations
98
+
99
+ Use this output to determine exact field names before writing any query or mutation. **Maximum 2 script runs.** If the entity still can't be found, ask the user — the object may not be deployed.
80
100
 
81
101
  ### Step 3: Generate Query
82
102
 
83
- Use the templates below. Every field name **must** be verified via grep.
103
+ Use the templates below. Every field name **must** be verified from the script output in Step 2.
84
104
 
85
105
  #### Read Query Template
86
106
 
@@ -131,70 +151,126 @@ mutation CreateAccount($input: AccountCreateInput!) {
131
151
  - Update: Include `Id`, only `updateable` fields
132
152
  - Delete: Include `Id` only
133
153
 
134
- ### Step 4: Validate & Test
154
+ #### Object Metadata & Picklist Values
135
155
 
136
- 1. **Lint**: `npx eslint <file>` from webapp dir
137
- 2. **Test**: Ask user before testing. For mutations, request input values — never fabricate data.
156
+ Use `uiapi { objectInfos(...) }` to fetch field metadata or picklist values. Pass **either** `apiNames` or `objectInfoInputs` never both in the same query.
138
157
 
139
- ```bash
140
- # From project root
141
- sf api request rest /services/data/v65.0/graphql \
142
- --method POST \
143
- --body '{"query":"..."}'
144
- ```
158
+ **Object metadata** (field labels, data types, CRUD flags):
145
159
 
146
- ---
160
+ ```typescript
161
+ const GET_OBJECT_INFO = gql`
162
+ query GetObjectInfo($apiNames: [String!]!) {
163
+ uiapi {
164
+ objectInfos(apiNames: $apiNames) {
165
+ ApiName
166
+ label
167
+ labelPlural
168
+ fields {
169
+ ApiName
170
+ label
171
+ dataType
172
+ updateable
173
+ createable
174
+ }
175
+ }
176
+ }
177
+ }
178
+ `;
147
179
 
148
- ## Webapp Integration (React)
180
+ const sdk = await createDataSDK();
181
+ const response = await sdk.graphql?.(GET_OBJECT_INFO, { apiNames: ["Account"] });
182
+ const objectInfos = response?.data?.uiapi?.objectInfos ?? [];
183
+ ```
149
184
 
150
- ### Pattern 1: External .graphql File (Recommended)
185
+ **Picklist values** (use `objectInfoInputs` + `... on PicklistField` inline fragment):
151
186
 
152
187
  ```typescript
153
- import { createDataSDK, type NodeOfConnection } from "@salesforce/sdk-data";
154
- import GET_ACCOUNTS from "./query/getAccounts.graphql?raw";
155
- import type { GetAccountsQuery } from "../graphql-operations-types";
188
+ const GET_PICKLIST_VALUES = gql`
189
+ query GetPicklistValues($objectInfoInputs: [ObjectInfoInput!]!) {
190
+ uiapi {
191
+ objectInfos(objectInfoInputs: $objectInfoInputs) {
192
+ ApiName
193
+ fields {
194
+ ApiName
195
+ ... on PicklistField {
196
+ picklistValuesByRecordTypeIDs {
197
+ recordTypeID
198
+ picklistValues {
199
+ label
200
+ value
201
+ }
202
+ }
203
+ }
204
+ }
205
+ }
206
+ }
207
+ }
208
+ `;
156
209
 
157
- const sdk = await createDataSDK();
158
- const response = await sdk.graphql?.<GetAccountsQuery>(GET_ACCOUNTS);
210
+ const response = await sdk.graphql?.(GET_PICKLIST_VALUES, {
211
+ objectInfoInputs: [{ objectApiName: "Account" }],
212
+ });
213
+ const fields = response?.data?.uiapi?.objectInfos?.[0]?.fields ?? [];
214
+ ```
159
215
 
160
- if (response?.errors?.length) {
161
- throw new Error(response.errors.map(e => e.message).join("; "));
162
- }
216
+ ### Step 4: Validate & Test
163
217
 
164
- const accounts = response?.data?.uiapi?.query?.Account?.edges?.map(e => e.node) ?? [];
218
+ 1. **Lint**: `npx eslint <file>` from webapp dir
219
+ 2. **Test**: Ask user before testing. For mutations, request input values — never fabricate data.
220
+
221
+ **If ESLint reports a GraphQL error** (e.g. `Cannot query field`, `Unknown type`, `Unknown argument`), the field or type name is wrong. Re-run the schema search script to find the correct name — do not guess:
222
+
223
+ ```bash
224
+ # From project root — re-check the entity that caused the error
225
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
165
226
  ```
166
227
 
167
- After creating/modifying `.graphql` files, run: `npm run graphql:codegen`
228
+ Then fix the query using the exact names from the script output.
229
+
230
+ ---
168
231
 
169
- ### Pattern 2: Inline gql Tag
232
+ ## Webapp Integration (React)
170
233
 
171
234
  ```typescript
172
235
  import { createDataSDK, gql } from "@salesforce/sdk-data";
173
236
 
174
- const GET_CURRENT_USER = gql`
175
- query CurrentUser {
176
- uiapi { currentUser { Id Name { value } } }
237
+ const GET_ACCOUNTS = gql`
238
+ query GetAccounts {
239
+ uiapi {
240
+ query {
241
+ Account(first: 10) {
242
+ edges {
243
+ node {
244
+ Id
245
+ Name @optional { value }
246
+ Industry @optional { value }
247
+ }
248
+ }
249
+ }
250
+ }
251
+ }
177
252
  }
178
253
  `;
179
254
 
180
- const response = await sdk.graphql?.<CurrentUserQuery>(GET_CURRENT_USER);
181
- ```
255
+ const sdk = await createDataSDK();
256
+ const response = await sdk.graphql?.(GET_ACCOUNTS);
182
257
 
183
- **Must use `gql` tag** — plain template strings bypass ESLint validation.
258
+ if (response?.errors?.length) {
259
+ throw new Error(response.errors.map(e => e.message).join("; "));
260
+ }
261
+
262
+ const accounts = response?.data?.uiapi?.query?.Account?.edges?.map(e => e.node) ?? [];
184
263
 
185
264
  ---
186
265
 
187
266
  ## REST API Patterns
188
267
 
189
- Use `sdk.fetch` when GraphQL is insufficient:
268
+ Use `sdk.fetch` when GraphQL is insufficient. See the [Supported APIs](#supported-apis) table for the full allowlist.
190
269
 
191
270
  ```typescript
192
271
  declare const __SF_API_VERSION__: string;
193
272
  const API_VERSION = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";
194
273
 
195
- // Chatter — current user
196
- const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/chatter/users/me`);
197
-
198
274
  // Connect — file upload config
199
275
  const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/connect/file/upload/config`);
200
276
 
@@ -205,6 +281,9 @@ const res = await sdk.fetch?.("/services/apexrest/auth/login", {
205
281
  headers: { "Content-Type": "application/json" },
206
282
  });
207
283
 
284
+ // UI API — record with metadata (prefer GraphQL for simple reads)
285
+ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/ui-api/records/${recordId}`);
286
+
208
287
  // Einstein LLM
209
288
  const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/einstein/llm/prompt/generations`, {
210
289
  method: "POST",
@@ -212,6 +291,17 @@ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/einstein/llm/promp
212
291
  });
213
292
  ```
214
293
 
294
+ **Current user**: Do not use Chatter (`/chatter/users/me`). Use GraphQL instead:
295
+
296
+ ```typescript
297
+ const GET_CURRENT_USER = gql`
298
+ query CurrentUser {
299
+ uiapi { currentUser { Id Name { value } } }
300
+ }
301
+ `;
302
+ const response = await sdk.graphql?.(GET_CURRENT_USER);
303
+ ```
304
+
215
305
  ---
216
306
 
217
307
  ## Directory Structure
@@ -222,47 +312,51 @@ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/einstein/llm/promp
222
312
  ├── sfdx-project.json
223
313
  └── force-app/main/default/webapplications/<app-name>/ ← webapp dir
224
314
  ├── package.json ← npm scripts
225
- ├── codegen.yml
226
315
  └── src/
227
- └── api/graphql-operations-types.ts ← generated types
228
316
  ```
229
317
 
230
318
  | Command | Run From | Why |
231
319
  |---------|----------|-----|
232
320
  | `npm run graphql:schema` | webapp dir | Script in webapp's package.json |
233
- | `npm run graphql:codegen` | webapp dir | Reads codegen.yml |
234
321
  | `npx eslint <file>` | webapp dir | Reads eslint.config.js |
235
- | `grep ... schema.graphql` | project root | Schema lives at root |
322
+ | `bash .a4drules/skills/using-salesforce-data/graphql-search.sh <Entity>` | project root | Schema lookup |
236
323
  | `sf api request rest` | project root | Needs sfdx-project.json |
237
324
 
238
325
  ---
239
326
 
240
327
  ## Quick Reference
241
328
 
242
- ### Grep Patterns (from project root)
329
+ ### Schema Lookup (from project root)
330
+
331
+ Run the search script to get all relevant schema info in one step:
332
+
333
+ ```bash
334
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
335
+ ```
243
336
 
244
- | Pattern | Context | Purpose |
245
- |---------|---------|---------|
246
- | `^type <Entity> implements Record` | `-A 100` | Entity fields |
247
- | `^input <Entity>_Filter` | `-A 50` | Filter options |
248
- | `^input <Entity>_OrderBy` | `-A 30` | Sort options |
249
- | `^input <Entity>CreateInput` | `-A 50` | Create mutation input |
250
- | `^input <Entity>UpdateInput` | `-A 50` | Update mutation input |
337
+ | Script Output Section | Used For |
338
+ |-----------------------|----------|
339
+ | Type definition | Field names, parent/child relationships |
340
+ | Filter options | `where:` conditions |
341
+ | Sort options | `orderBy:` |
342
+ | CreateRepresentation | Create mutation field list |
343
+ | UpdateRepresentation | Update mutation field list |
251
344
 
252
345
  ### Error Categories
253
346
 
254
347
  | Error Contains | Resolution |
255
348
  |----------------|------------|
349
+ | `Cannot query field` | Field name is wrong — run `graphql-search.sh <Entity>` and use the exact name from the Type definition section |
350
+ | `Unknown type` | Type name is wrong — run `graphql-search.sh <Entity>` to confirm the correct PascalCase entity name |
351
+ | `Unknown argument` | Argument name is wrong — run `graphql-search.sh <Entity>` and check Filter or OrderBy sections |
256
352
  | `invalid syntax` | Fix syntax per error message |
257
- | `validation error` | Re-grep to verify field name |
353
+ | `validation error` | Field name is wrong — run `graphql-search.sh <Entity>` to verify |
258
354
  | `VariableTypeMismatch` | Correct argument type from schema |
259
355
  | `invalid cross reference id` | Entity deleted — ask for valid Id |
260
356
 
261
357
  ### Checklist
262
358
 
263
- - [ ] All field names verified via grep
359
+ - [ ] All field names verified via search script (Step 2)
264
360
  - [ ] `@optional` applied to record fields (reads)
265
361
  - [ ] Optional chaining in consuming code
266
- - [ ] `gql` tag used (not plain strings)
267
362
  - [ ] Lint passes: `npx eslint <file>`
268
- - [ ] Types generated: `npm run graphql:codegen`
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env bash
2
+ # graphql-search.sh — Look up one or more Salesforce entities in schema.graphql.
3
+ #
4
+ # Run from the SFDX project root (where schema.graphql lives):
5
+ # bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account
6
+ # bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account Contact Opportunity
7
+ #
8
+ # Pass a custom schema path with -s / --schema:
9
+ # bash .a4drules/skills/using-salesforce-data/graphql-search.sh -s /path/to/schema.graphql Account
10
+ # bash .a4drules/skills/using-salesforce-data/graphql-search.sh --schema ./other/schema.graphql Account Contact
11
+ #
12
+ # Output sections per entity:
13
+ # 1. Type definition — all fields and relationships
14
+ # 2. Filter options — <Entity>_Filter input (for `where:`)
15
+ # 3. Sort options — <Entity>_OrderBy input (for `orderBy:`)
16
+ # 4. Create input — <Entity>CreateRepresentation (for create mutations)
17
+ # 5. Update input — <Entity>UpdateRepresentation (for update mutations)
18
+
19
+ SCHEMA="./schema.graphql"
20
+
21
+ # ── Argument parsing ─────────────────────────────────────────────────────────
22
+
23
+ while [[ $# -gt 0 ]]; do
24
+ case "$1" in
25
+ -s|--schema)
26
+ if [[ -z "${2-}" || "$2" == -* ]]; then
27
+ echo "ERROR: --schema requires a file path argument"
28
+ exit 1
29
+ fi
30
+ SCHEMA="$2"
31
+ shift 2
32
+ ;;
33
+ --)
34
+ shift
35
+ break
36
+ ;;
37
+ -*)
38
+ echo "ERROR: Unknown option: $1"
39
+ echo "Usage: bash $0 [-s <schema-path>] <EntityName> [EntityName2 ...]"
40
+ exit 1
41
+ ;;
42
+ *)
43
+ break
44
+ ;;
45
+ esac
46
+ done
47
+
48
+ if [ $# -eq 0 ]; then
49
+ echo "Usage: bash $0 [-s <schema-path>] <EntityName> [EntityName2 ...]"
50
+ echo "Example: bash $0 Account"
51
+ echo "Example: bash $0 Account Contact Opportunity"
52
+ echo "Example: bash $0 --schema /path/to/schema.graphql Account"
53
+ exit 1
54
+ fi
55
+
56
+ if [ ! -f "$SCHEMA" ]; then
57
+ echo "ERROR: schema.graphql not found at $SCHEMA"
58
+ echo " Make sure you are running from the SFDX project root, or pass the path explicitly:"
59
+ echo " bash $0 --schema <path/to/schema.graphql> <EntityName>"
60
+ echo " If the file is missing entirely, generate it from the webapp dir:"
61
+ echo " cd force-app/main/default/webapplications/<app-name> && npm run graphql:schema"
62
+ exit 1
63
+ fi
64
+
65
+ # ── Helper: extract lines from a grep match through the closing brace ────────
66
+ # Prints up to MAX_LINES lines after (and including) the first match of PATTERN.
67
+ # Uses a generous line count — blocks are always closed by a "}" line.
68
+
69
+ extract_block() {
70
+ local label="$1"
71
+ local pattern="$2"
72
+ local max_lines="$3"
73
+
74
+ local match
75
+ match=$(grep -nE "$pattern" "$SCHEMA" | head -1)
76
+
77
+ if [ -z "$match" ]; then
78
+ echo " (not found: $pattern)"
79
+ return
80
+ fi
81
+
82
+ echo "### $label"
83
+ grep -E "$pattern" "$SCHEMA" -A "$max_lines" | \
84
+ awk '/^\}$/{print; exit} {print}' | \
85
+ head -n "$max_lines"
86
+ echo ""
87
+ }
88
+
89
+ # ── Main loop ────────────────────────────────────────────────────────────────
90
+
91
+ for ENTITY in "$@"; do
92
+ echo ""
93
+ echo "======================================================================"
94
+ echo " SCHEMA LOOKUP: $ENTITY"
95
+ echo "======================================================================"
96
+ echo ""
97
+
98
+ # 1. Type definition — all fields and relationships
99
+ extract_block \
100
+ "Type definition — fields and relationships" \
101
+ "^type ${ENTITY} implements Record" \
102
+ 200
103
+
104
+ # 2. Filter input — used in `where:` arguments
105
+ extract_block \
106
+ "Filter options — use in where: { ... }" \
107
+ "^input ${ENTITY}_Filter" \
108
+ 100
109
+
110
+ # 3. OrderBy input — used in `orderBy:` arguments
111
+ extract_block \
112
+ "Sort options — use in orderBy: { ... }" \
113
+ "^input ${ENTITY}_OrderBy" \
114
+ 60
115
+
116
+ # 4. Create mutation inputs
117
+ extract_block \
118
+ "Create mutation wrapper — ${ENTITY}CreateInput" \
119
+ "^input ${ENTITY}CreateInput" \
120
+ 10
121
+
122
+ extract_block \
123
+ "Create mutation fields — ${ENTITY}CreateRepresentation" \
124
+ "^input ${ENTITY}CreateRepresentation" \
125
+ 100
126
+
127
+ # 5. Update mutation inputs
128
+ extract_block \
129
+ "Update mutation wrapper — ${ENTITY}UpdateInput" \
130
+ "^input ${ENTITY}UpdateInput" \
131
+ 10
132
+
133
+ extract_block \
134
+ "Update mutation fields — ${ENTITY}UpdateRepresentation" \
135
+ "^input ${ENTITY}UpdateRepresentation" \
136
+ 100
137
+
138
+ echo ""
139
+ done
@@ -0,0 +1,353 @@
1
+ # Salesforce Data Access
2
+
3
+ - **Fetch or display Salesforce data** — Query records (Account, Contact, Opportunity, custom objects) to show in a component
4
+ - **Create, update, or delete records** — Perform mutations on Salesforce data
5
+ - **Add data fetching to a component** — Wire up a React component to Salesforce data
6
+ - **Call REST APIs** — Use Connect REST, Apex REST, or UI API endpoints
7
+ - **Explore the org schema** — Discover available objects, fields, or relationships
8
+
9
+ ## Data SDK Requirement
10
+
11
+ > **All Salesforce data access MUST use the Data SDK** (`@salesforce/sdk-data`). The SDK handles authentication, CSRF, and base URL resolution. Never use `fetch()` or `axios` directly.
12
+
13
+ ```typescript
14
+ import { createDataSDK, gql } from "@salesforce/sdk-data";
15
+
16
+ const sdk = await createDataSDK();
17
+
18
+ // GraphQL for record queries/mutations (PREFERRED)
19
+ const response = await sdk.graphql?.<ResponseType>(query, variables);
20
+
21
+ // REST for Connect REST, Apex REST, UI API (when GraphQL insufficient)
22
+ const res = await sdk.fetch?.("/services/apexrest/my-resource");
23
+ ```
24
+
25
+ **Always use optional chaining** (`sdk.graphql?.()`, `sdk.fetch?.()`) — these methods may be undefined in some surfaces.
26
+
27
+ ## Supported APIs
28
+
29
+ **Only the following APIs are permitted.** Any endpoint not listed here must not be used.
30
+
31
+ | API | Method | Endpoints / Use Case |
32
+ |-----|--------|----------------------|
33
+ | GraphQL | `sdk.graphql` | All record queries and mutations via `uiapi { }` namespace |
34
+ | UI API REST | `sdk.fetch` | `/services/data/v{ver}/ui-api/records/{id}` — record metadata when GraphQL is insufficient |
35
+ | Apex REST | `sdk.fetch` | `/services/apexrest/{resource}` — custom server-side logic, aggregates, multi-step transactions |
36
+ | Connect REST | `sdk.fetch` | `/services/data/v{ver}/connect/file/upload/config` — file upload config |
37
+ | Einstein LLM | `sdk.fetch` | `/services/data/v{ver}/einstein/llm/prompt/generations` — AI text generation |
38
+
39
+ **Not supported:**
40
+
41
+ - **Enterprise REST query endpoint** (`/services/data/v*/query` with SOQL) — blocked at the proxy level. Use GraphQL for record reads; use Apex REST if server-side SOQL aggregates are required.
42
+ - **Aura-enabled Apex** (`@AuraEnabled`) — an LWC/Aura pattern with no invocation path from React webapps.
43
+ - **Chatter API** (`/chatter/users/me`) — use `uiapi { currentUser { ... } }` in a GraphQL query instead.
44
+ - **Any other Salesforce REST endpoint** not listed in the supported table above.
45
+
46
+ ## Decision: GraphQL vs REST
47
+
48
+ | Need | Method | Example |
49
+ |------|--------|---------|
50
+ | Query/mutate records | `sdk.graphql` | Account, Contact, custom objects |
51
+ | Current user info | `sdk.graphql` | `uiapi { currentUser { Id Name { value } } }` |
52
+ | UI API record metadata | `sdk.fetch` | `/ui-api/records/{id}` |
53
+ | Connect REST | `sdk.fetch` | `/connect/file/upload/config` |
54
+ | Apex REST | `sdk.fetch` | `/services/apexrest/auth/login` |
55
+ | Einstein LLM | `sdk.fetch` | `/einstein/llm/prompt/generations` |
56
+
57
+ **GraphQL is preferred** for record operations. Use REST only when GraphQL doesn't cover the use case.
58
+
59
+ ---
60
+
61
+ ## GraphQL Workflow
62
+
63
+ ### Step 1: Acquire Schema
64
+
65
+ The `schema.graphql` file (265K+ lines) is the source of truth. **Never open or parse it directly.**
66
+
67
+ 1. Check if `schema.graphql` exists at the SFDX project root
68
+ 2. If missing, run from the **webapp dir**: `npm run graphql:schema`
69
+ 3. Custom objects appear only after metadata is deployed
70
+
71
+ ### Step 2: Look Up Entity Schema
72
+
73
+ Map user intent to PascalCase names ("accounts" → `Account`), then **run the search script from the project root**:
74
+
75
+ ```bash
76
+ # From project root — look up all relevant schema info for one or more entities
77
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account
78
+
79
+ # Multiple entities at once
80
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account Contact Opportunity
81
+ ```
82
+
83
+ The script outputs five sections per entity:
84
+ 1. **Type definition** — all queryable fields and relationships
85
+ 2. **Filter options** — available fields for `where:` conditions
86
+ 3. **Sort options** — available fields for `orderBy:`
87
+ 4. **Create input** — fields accepted by create mutations
88
+ 5. **Update input** — fields accepted by update mutations
89
+
90
+ Use this output to determine exact field names before writing any query or mutation. **Maximum 2 script runs.** If the entity still can't be found, ask the user — the object may not be deployed.
91
+
92
+ ### Step 3: Generate Query
93
+
94
+ Use the templates below. Every field name **must** be verified from the script output in Step 2.
95
+
96
+ #### Read Query Template
97
+
98
+ ```graphql
99
+ query GetAccounts {
100
+ uiapi {
101
+ query {
102
+ Account(where: { Industry: { eq: "Technology" } }, first: 10) {
103
+ edges {
104
+ node {
105
+ Id
106
+ Name @optional { value }
107
+ Industry @optional { value }
108
+ # Parent relationship
109
+ Owner @optional { Name { value } }
110
+ # Child relationship
111
+ Contacts @optional {
112
+ edges { node { Name @optional { value } } }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
122
+ **FLS Resilience**: Apply `@optional` to all record fields. The server omits inaccessible fields instead of failing. Consuming code must use optional chaining:
123
+
124
+ ```typescript
125
+ const name = node.Name?.value ?? "";
126
+ ```
127
+
128
+ #### Mutation Template
129
+
130
+ ```graphql
131
+ mutation CreateAccount($input: AccountCreateInput!) {
132
+ uiapi {
133
+ AccountCreate(input: $input) {
134
+ Record { Id Name { value } }
135
+ }
136
+ }
137
+ }
138
+ ```
139
+
140
+ **Mutation constraints:**
141
+ - Create: Include required fields, only `createable` fields, no child relationships
142
+ - Update: Include `Id`, only `updateable` fields
143
+ - Delete: Include `Id` only
144
+
145
+ #### Object Metadata & Picklist Values
146
+
147
+ Use `uiapi { objectInfos(...) }` to fetch field metadata or picklist values. Pass **either** `apiNames` or `objectInfoInputs` — never both in the same query.
148
+
149
+ **Object metadata** (field labels, data types, CRUD flags):
150
+
151
+ ```typescript
152
+ const GET_OBJECT_INFO = gql`
153
+ query GetObjectInfo($apiNames: [String!]!) {
154
+ uiapi {
155
+ objectInfos(apiNames: $apiNames) {
156
+ ApiName
157
+ label
158
+ labelPlural
159
+ fields {
160
+ ApiName
161
+ label
162
+ dataType
163
+ updateable
164
+ createable
165
+ }
166
+ }
167
+ }
168
+ }
169
+ `;
170
+
171
+ const sdk = await createDataSDK();
172
+ const response = await sdk.graphql?.(GET_OBJECT_INFO, { apiNames: ["Account"] });
173
+ const objectInfos = response?.data?.uiapi?.objectInfos ?? [];
174
+ ```
175
+
176
+ **Picklist values** (use `objectInfoInputs` + `... on PicklistField` inline fragment):
177
+
178
+ ```typescript
179
+ const GET_PICKLIST_VALUES = gql`
180
+ query GetPicklistValues($objectInfoInputs: [ObjectInfoInput!]!) {
181
+ uiapi {
182
+ objectInfos(objectInfoInputs: $objectInfoInputs) {
183
+ ApiName
184
+ fields {
185
+ ApiName
186
+ ... on PicklistField {
187
+ picklistValuesByRecordTypeIDs {
188
+ recordTypeID
189
+ picklistValues {
190
+ label
191
+ value
192
+ }
193
+ }
194
+ }
195
+ }
196
+ }
197
+ }
198
+ }
199
+ `;
200
+
201
+ const response = await sdk.graphql?.(GET_PICKLIST_VALUES, {
202
+ objectInfoInputs: [{ objectApiName: "Account" }],
203
+ });
204
+ const fields = response?.data?.uiapi?.objectInfos?.[0]?.fields ?? [];
205
+ ```
206
+
207
+ ### Step 4: Validate & Test
208
+
209
+ 1. **Lint**: `npx eslint <file>` from webapp dir
210
+ 2. **Test**: Ask user before testing. For mutations, request input values — never fabricate data.
211
+
212
+ **If ESLint reports a GraphQL error** (e.g. `Cannot query field`, `Unknown type`, `Unknown argument`), the field or type name is wrong. Re-run the schema search script to find the correct name — do not guess:
213
+
214
+ ```bash
215
+ # From project root — re-check the entity that caused the error
216
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
217
+ ```
218
+
219
+ Then fix the query using the exact names from the script output.
220
+
221
+ ---
222
+
223
+ ## Webapp Integration (React)
224
+
225
+ ```typescript
226
+ import { createDataSDK, gql } from "@salesforce/sdk-data";
227
+
228
+ const GET_ACCOUNTS = gql`
229
+ query GetAccounts {
230
+ uiapi {
231
+ query {
232
+ Account(first: 10) {
233
+ edges {
234
+ node {
235
+ Id
236
+ Name @optional { value }
237
+ Industry @optional { value }
238
+ }
239
+ }
240
+ }
241
+ }
242
+ }
243
+ }
244
+ `;
245
+
246
+ const sdk = await createDataSDK();
247
+ const response = await sdk.graphql?.(GET_ACCOUNTS);
248
+
249
+ if (response?.errors?.length) {
250
+ throw new Error(response.errors.map(e => e.message).join("; "));
251
+ }
252
+
253
+ const accounts = response?.data?.uiapi?.query?.Account?.edges?.map(e => e.node) ?? [];
254
+
255
+ ---
256
+
257
+ ## REST API Patterns
258
+
259
+ Use `sdk.fetch` when GraphQL is insufficient. See the [Supported APIs](#supported-apis) table for the full allowlist.
260
+
261
+ ```typescript
262
+ declare const __SF_API_VERSION__: string;
263
+ const API_VERSION = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";
264
+
265
+ // Connect — file upload config
266
+ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/connect/file/upload/config`);
267
+
268
+ // Apex REST (no version in path)
269
+ const res = await sdk.fetch?.("/services/apexrest/auth/login", {
270
+ method: "POST",
271
+ body: JSON.stringify({ email, password }),
272
+ headers: { "Content-Type": "application/json" },
273
+ });
274
+
275
+ // UI API — record with metadata (prefer GraphQL for simple reads)
276
+ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/ui-api/records/${recordId}`);
277
+
278
+ // Einstein LLM
279
+ const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/einstein/llm/prompt/generations`, {
280
+ method: "POST",
281
+ body: JSON.stringify({ promptTextorId: prompt }),
282
+ });
283
+ ```
284
+
285
+ **Current user**: Do not use Chatter (`/chatter/users/me`). Use GraphQL instead:
286
+
287
+ ```typescript
288
+ const GET_CURRENT_USER = gql`
289
+ query CurrentUser {
290
+ uiapi { currentUser { Id Name { value } } }
291
+ }
292
+ `;
293
+ const response = await sdk.graphql?.(GET_CURRENT_USER);
294
+ ```
295
+
296
+ ---
297
+
298
+ ## Directory Structure
299
+
300
+ ```
301
+ <project-root>/ ← SFDX project root
302
+ ├── schema.graphql ← grep target (lives here)
303
+ ├── sfdx-project.json
304
+ └── force-app/main/default/webapplications/<app-name>/ ← webapp dir
305
+ ├── package.json ← npm scripts
306
+ └── src/
307
+ ```
308
+
309
+ | Command | Run From | Why |
310
+ |---------|----------|-----|
311
+ | `npm run graphql:schema` | webapp dir | Script in webapp's package.json |
312
+ | `npx eslint <file>` | webapp dir | Reads eslint.config.js |
313
+ | `bash .a4drules/skills/using-salesforce-data/graphql-search.sh <Entity>` | project root | Schema lookup |
314
+ | `sf api request rest` | project root | Needs sfdx-project.json |
315
+
316
+ ---
317
+
318
+ ## Quick Reference
319
+
320
+ ### Schema Lookup (from project root)
321
+
322
+ Run the search script to get all relevant schema info in one step:
323
+
324
+ ```bash
325
+ bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
326
+ ```
327
+
328
+ | Script Output Section | Used For |
329
+ |-----------------------|----------|
330
+ | Type definition | Field names, parent/child relationships |
331
+ | Filter options | `where:` conditions |
332
+ | Sort options | `orderBy:` |
333
+ | CreateRepresentation | Create mutation field list |
334
+ | UpdateRepresentation | Update mutation field list |
335
+
336
+ ### Error Categories
337
+
338
+ | Error Contains | Resolution |
339
+ |----------------|------------|
340
+ | `Cannot query field` | Field name is wrong — run `graphql-search.sh <Entity>` and use the exact name from the Type definition section |
341
+ | `Unknown type` | Type name is wrong — run `graphql-search.sh <Entity>` to confirm the correct PascalCase entity name |
342
+ | `Unknown argument` | Argument name is wrong — run `graphql-search.sh <Entity>` and check Filter or OrderBy sections |
343
+ | `invalid syntax` | Fix syntax per error message |
344
+ | `validation error` | Field name is wrong — run `graphql-search.sh <Entity>` to verify |
345
+ | `VariableTypeMismatch` | Correct argument type from schema |
346
+ | `invalid cross reference id` | Entity deleted — ask for valid Id |
347
+
348
+ ### Checklist
349
+
350
+ - [ ] All field names verified via search script (Step 2)
351
+ - [ ] `@optional` applied to record fields (reads)
352
+ - [ ] Optional chaining in consuming code
353
+ - [ ] Lint passes: `npx eslint <file>`
@@ -0,0 +1,16 @@
1
+ # UI Platform Rule
2
+
3
+ **All new UI must be built as a Salesforce Web Application.**
4
+
5
+ When any task involves creating a new UI, frontend, page, dashboard, form, or user-facing feature:
6
+
7
+ 1. Use `sf webapp generate` to scaffold the web app inside the SFDX project — do not use `create-react-app`, standalone Vite, or any other scaffold.
8
+ 2. The app must live under `<sfdx-source>/webapplications/<AppName>/` as a WebApplication bundle.
9
+ 3. Do not build new UIs as LWC components, Aura components, or Visualforce pages.
10
+
11
+ Invoke the `creating-webapp` skill (`.a4drules/skills/creating-webapp/`) for the full setup workflow.
12
+
13
+ ## Data Access (MUST FOLLOW)
14
+
15
+ - **Never hardcode data in the app.** All data displayed in the UI must come from live Salesforce data fetching — no static arrays, mock objects, or placeholder values in production code.
16
+ - **Always invoke the `using-salesforce-data` skill** (`.a4drules/skills/using-salesforce-data/`) before writing any data access code. All implementation must be derived from that skill.
package/dist/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.112.3](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.112.2...v1.112.3) (2026-03-20)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **blitz:** make changes to rules and skills for blitz ([#332](https://github.com/salesforce-experience-platform-emu/webapps/issues/332)) ([f7baaa4](https://github.com/salesforce-experience-platform-emu/webapps/commit/f7baaa4d263b56ccea35b9e6bf57556edf22c530))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [1.112.2](https://github.com/salesforce-experience-platform-emu/webapps/compare/v1.112.1...v1.112.2) (2026-03-20)
7
18
 
8
19
  **Note:** Version bump only for package @salesforce/webapp-template-base-sfdx-project-experimental
@@ -15,8 +15,8 @@
15
15
  "graphql:schema": "node scripts/get-graphql-schema.mjs"
16
16
  },
17
17
  "dependencies": {
18
- "@salesforce/sdk-data": "^1.112.2",
19
- "@salesforce/webapp-experimental": "^1.112.2",
18
+ "@salesforce/sdk-data": "^1.112.3",
19
+ "@salesforce/webapp-experimental": "^1.112.3",
20
20
  "@tailwindcss/vite": "^4.1.17",
21
21
  "class-variance-authority": "^0.7.1",
22
22
  "clsx": "^2.1.1",
@@ -43,7 +43,7 @@
43
43
  "@graphql-eslint/eslint-plugin": "^4.1.0",
44
44
  "@graphql-tools/utils": "^11.0.0",
45
45
  "@playwright/test": "^1.49.0",
46
- "@salesforce/vite-plugin-webapp-experimental": "^1.112.2",
46
+ "@salesforce/vite-plugin-webapp-experimental": "^1.112.3",
47
47
  "@testing-library/jest-dom": "^6.6.3",
48
48
  "@testing-library/react": "^16.1.0",
49
49
  "@testing-library/user-event": "^14.5.2",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.112.2",
3
+ "version": "1.112.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
9
- "version": "1.112.2",
9
+ "version": "1.112.3",
10
10
  "license": "SEE LICENSE IN LICENSE.txt",
11
11
  "devDependencies": {
12
12
  "@lwc/eslint-plugin-lwc": "^3.3.0",
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-base-sfdx-project-experimental",
3
- "version": "1.112.2",
3
+ "version": "1.112.3",
4
4
  "description": "Base SFDX project template",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "publishConfig": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/webapp-template-feature-react-global-search-experimental",
3
- "version": "1.112.2",
3
+ "version": "1.112.3",
4
4
  "description": "Global search feature for Salesforce objects with filtering and pagination",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "",