@schandlergarcia/sf-web-components 1.0.0
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.
- package/.a4drules/skills/building-data-visualization/SKILL.md +72 -0
- package/.a4drules/skills/building-data-visualization/implementation/bar-line-chart.md +316 -0
- package/.a4drules/skills/building-data-visualization/implementation/dashboard-layout.md +189 -0
- package/.a4drules/skills/building-data-visualization/implementation/donut-chart.md +181 -0
- package/.a4drules/skills/building-data-visualization/implementation/stat-card.md +150 -0
- package/.a4drules/skills/building-react-components/SKILL.md +96 -0
- package/.a4drules/skills/building-react-components/implementation/component.md +78 -0
- package/.a4drules/skills/building-react-components/implementation/header-footer.md +132 -0
- package/.a4drules/skills/building-react-components/implementation/page.md +93 -0
- package/.a4drules/skills/configuring-csp-trusted-sites/SKILL.md +90 -0
- package/.a4drules/skills/configuring-csp-trusted-sites/implementation/metadata-format.md +281 -0
- package/.a4drules/skills/configuring-webapp-metadata/SKILL.md +158 -0
- package/.a4drules/skills/creating-webapp/SKILL.md +140 -0
- package/.a4drules/skills/deploying-to-salesforce/SKILL.md +226 -0
- package/.a4drules/skills/implementing-file-upload/SKILL.md +396 -0
- package/.a4drules/skills/installing-webapp-features/SKILL.md +210 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/SKILL.md +186 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/constraints.md +134 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/examples.md +132 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/style-tokens.md +101 -0
- package/.a4drules/skills/managing-agentforce-conversation-client/references/troubleshooting.md +57 -0
- package/.a4drules/skills/using-salesforce-data/SKILL.md +363 -0
- package/.a4drules/skills/using-salesforce-data/graphql-search.sh +139 -0
- package/.a4drules/webapp-data.md +353 -0
- package/.a4drules/webapp-ui.md +16 -0
- package/README.md +124 -0
- package/dist/components/library/cards/ActionList.js +27 -0
- package/dist/components/library/cards/ActionList.js.map +1 -0
- package/dist/components/library/cards/ActivityCard.js +40 -0
- package/dist/components/library/cards/ActivityCard.js.map +1 -0
- package/dist/components/library/cards/BaseCard.js +89 -0
- package/dist/components/library/cards/BaseCard.js.map +1 -0
- package/dist/components/library/cards/CalloutCard.js +28 -0
- package/dist/components/library/cards/CalloutCard.js.map +1 -0
- package/dist/components/library/cards/ChartCard.js +79 -0
- package/dist/components/library/cards/ChartCard.js.map +1 -0
- package/dist/components/library/cards/FeedPanel.js +38 -0
- package/dist/components/library/cards/FeedPanel.js.map +1 -0
- package/dist/components/library/cards/ListCard.js +112 -0
- package/dist/components/library/cards/ListCard.js.map +1 -0
- package/dist/components/library/cards/MetricCard.js +86 -0
- package/dist/components/library/cards/MetricCard.js.map +1 -0
- package/dist/components/library/cards/MetricsStrip.js +60 -0
- package/dist/components/library/cards/MetricsStrip.js.map +1 -0
- package/dist/components/library/cards/SectionCard.js +59 -0
- package/dist/components/library/cards/SectionCard.js.map +1 -0
- package/dist/components/library/cards/StatusCard.js +137 -0
- package/dist/components/library/cards/StatusCard.js.map +1 -0
- package/dist/components/library/cards/TableCard.js +244 -0
- package/dist/components/library/cards/TableCard.js.map +1 -0
- package/dist/components/library/cards/WidgetCard.js +60 -0
- package/dist/components/library/cards/WidgetCard.js.map +1 -0
- package/dist/components/library/charts/D3Chart.js +74 -0
- package/dist/components/library/charts/D3Chart.js.map +1 -0
- package/dist/components/library/charts/D3ChartTemplates.js +44 -0
- package/dist/components/library/charts/D3ChartTemplates.js.map +1 -0
- package/dist/components/library/charts/GeoMap.js +229 -0
- package/dist/components/library/charts/GeoMap.js.map +1 -0
- package/dist/components/library/chat/ChatBar.js +194 -0
- package/dist/components/library/chat/ChatBar.js.map +1 -0
- package/dist/components/library/chat/ChatInput.js +67 -0
- package/dist/components/library/chat/ChatInput.js.map +1 -0
- package/dist/components/library/chat/ChatMessage.js +112 -0
- package/dist/components/library/chat/ChatMessage.js.map +1 -0
- package/dist/components/library/chat/ChatMessageList.js +50 -0
- package/dist/components/library/chat/ChatMessageList.js.map +1 -0
- package/dist/components/library/chat/ChatPanel.js +77 -0
- package/dist/components/library/chat/ChatPanel.js.map +1 -0
- package/dist/components/library/chat/ChatSuggestions.js +22 -0
- package/dist/components/library/chat/ChatSuggestions.js.map +1 -0
- package/dist/components/library/chat/ChatToolCall.js +87 -0
- package/dist/components/library/chat/ChatToolCall.js.map +1 -0
- package/dist/components/library/chat/ChatTypingIndicator.js +20 -0
- package/dist/components/library/chat/ChatTypingIndicator.js.map +1 -0
- package/dist/components/library/chat/ChatWelcome.js +24 -0
- package/dist/components/library/chat/ChatWelcome.js.map +1 -0
- package/dist/components/library/chat/useChatState.js +77 -0
- package/dist/components/library/chat/useChatState.js.map +1 -0
- package/dist/components/library/data/DataModeProvider.js +47 -0
- package/dist/components/library/data/DataModeProvider.js.map +1 -0
- package/dist/components/library/data/DataModeToggle.js +28 -0
- package/dist/components/library/data/DataModeToggle.js.map +1 -0
- package/dist/components/library/data/filterUtils.js +71 -0
- package/dist/components/library/data/filterUtils.js.map +1 -0
- package/dist/components/library/data/useDataSource.js +13 -0
- package/dist/components/library/data/useDataSource.js.map +1 -0
- package/dist/components/library/data/usePageFilters.js +46 -0
- package/dist/components/library/data/usePageFilters.js.map +1 -0
- package/dist/components/library/filters/FilterBar.js +89 -0
- package/dist/components/library/filters/FilterBar.js.map +1 -0
- package/dist/components/library/filters/SearchFilter.js +44 -0
- package/dist/components/library/filters/SearchFilter.js.map +1 -0
- package/dist/components/library/filters/SelectFilter.js +44 -0
- package/dist/components/library/filters/SelectFilter.js.map +1 -0
- package/dist/components/library/filters/ToggleFilter.js +48 -0
- package/dist/components/library/filters/ToggleFilter.js.map +1 -0
- package/dist/components/library/forms/FormField.js +256 -0
- package/dist/components/library/forms/FormField.js.map +1 -0
- package/dist/components/library/forms/FormModal.js +161 -0
- package/dist/components/library/forms/FormModal.js.map +1 -0
- package/dist/components/library/forms/FormRenderer.js +32 -0
- package/dist/components/library/forms/FormRenderer.js.map +1 -0
- package/dist/components/library/forms/FormSection.js +49 -0
- package/dist/components/library/forms/FormSection.js.map +1 -0
- package/dist/components/library/forms/useFormState.js +85 -0
- package/dist/components/library/forms/useFormState.js.map +1 -0
- package/dist/components/library/heroui/Accordion.js +12 -0
- package/dist/components/library/heroui/Accordion.js.map +1 -0
- package/dist/components/library/heroui/Alert.js +12 -0
- package/dist/components/library/heroui/Alert.js.map +1 -0
- package/dist/components/library/heroui/Badge.js +12 -0
- package/dist/components/library/heroui/Badge.js.map +1 -0
- package/dist/components/library/heroui/Breadcrumbs.js +12 -0
- package/dist/components/library/heroui/Breadcrumbs.js.map +1 -0
- package/dist/components/library/heroui/Button.js +18 -0
- package/dist/components/library/heroui/Button.js.map +1 -0
- package/dist/components/library/heroui/Card.js +12 -0
- package/dist/components/library/heroui/Card.js.map +1 -0
- package/dist/components/library/heroui/Drawer.js +12 -0
- package/dist/components/library/heroui/Drawer.js.map +1 -0
- package/dist/components/library/heroui/Dropdown.js +12 -0
- package/dist/components/library/heroui/Dropdown.js.map +1 -0
- package/dist/components/library/heroui/Input.js +10 -0
- package/dist/components/library/heroui/Input.js.map +1 -0
- package/dist/components/library/heroui/Kbd.js +12 -0
- package/dist/components/library/heroui/Kbd.js.map +1 -0
- package/dist/components/library/heroui/Meter.js +12 -0
- package/dist/components/library/heroui/Meter.js.map +1 -0
- package/dist/components/library/heroui/Modal.js +12 -0
- package/dist/components/library/heroui/Modal.js.map +1 -0
- package/dist/components/library/heroui/Pagination.js +12 -0
- package/dist/components/library/heroui/Pagination.js.map +1 -0
- package/dist/components/library/heroui/ProgressBar.js +12 -0
- package/dist/components/library/heroui/ProgressBar.js.map +1 -0
- package/dist/components/library/heroui/ProgressCircle.js +12 -0
- package/dist/components/library/heroui/ProgressCircle.js.map +1 -0
- package/dist/components/library/heroui/ScrollShadow.js +12 -0
- package/dist/components/library/heroui/ScrollShadow.js.map +1 -0
- package/dist/components/library/heroui/Select.js +12 -0
- package/dist/components/library/heroui/Select.js.map +1 -0
- package/dist/components/library/heroui/Separator.js +12 -0
- package/dist/components/library/heroui/Separator.js.map +1 -0
- package/dist/components/library/heroui/Skeleton.js +12 -0
- package/dist/components/library/heroui/Skeleton.js.map +1 -0
- package/dist/components/library/heroui/Tabs.js +12 -0
- package/dist/components/library/heroui/Tabs.js.map +1 -0
- package/dist/components/library/heroui/Toast.js +13 -0
- package/dist/components/library/heroui/Toast.js.map +1 -0
- package/dist/components/library/heroui/Toggle.js +12 -0
- package/dist/components/library/heroui/Toggle.js.map +1 -0
- package/dist/components/library/heroui/Tooltip.js +12 -0
- package/dist/components/library/heroui/Tooltip.js.map +1 -0
- package/dist/components/library/layout/PageContainer.js +9 -0
- package/dist/components/library/layout/PageContainer.js.map +1 -0
- package/dist/components/library/skeletons/CardSkeleton.js +29 -0
- package/dist/components/library/skeletons/CardSkeleton.js.map +1 -0
- package/dist/components/library/theme/AppThemeProvider.js +55 -0
- package/dist/components/library/theme/AppThemeProvider.js.map +1 -0
- package/dist/components/library/theme/tokens.js +55 -0
- package/dist/components/library/theme/tokens.js.map +1 -0
- package/dist/components/library/ui/Avatar.js +33 -0
- package/dist/components/library/ui/Avatar.js.map +1 -0
- package/dist/components/library/ui/Button.js +50 -0
- package/dist/components/library/ui/Button.js.map +1 -0
- package/dist/components/library/ui/Card.js +21 -0
- package/dist/components/library/ui/Card.js.map +1 -0
- package/dist/components/library/ui/Chip.js +31 -0
- package/dist/components/library/ui/Chip.js.map +1 -0
- package/dist/components/library/ui/Container.js +42 -0
- package/dist/components/library/ui/Container.js.map +1 -0
- package/dist/components/library/ui/EmptyState.js +27 -0
- package/dist/components/library/ui/EmptyState.js.map +1 -0
- package/dist/components/library/ui/Input.js +22 -0
- package/dist/components/library/ui/Input.js.map +1 -0
- package/dist/components/library/ui/Spinner.js +64 -0
- package/dist/components/library/ui/Spinner.js.map +1 -0
- package/dist/components/library/ui/Text.js +43 -0
- package/dist/components/library/ui/Text.js.map +1 -0
- package/dist/components/library/ui/Toggle.js +47 -0
- package/dist/components/library/ui/Toggle.js.map +1 -0
- package/dist/components/workspace/ComponentRegistry.js +231 -0
- package/dist/components/workspace/ComponentRegistry.js.map +1 -0
- package/dist/index.js +185 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.js +9 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/node_modules/clsx/dist/clsx.js +17 -0
- package/dist/node_modules/clsx/dist/clsx.js.map +1 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js +2925 -0
- package/dist/node_modules/tailwind-merge/dist/bundle-mjs.js.map +1 -0
- package/package.json +81 -0
- package/scripts/get-graphql-schema.mjs +68 -0
- package/scripts/reset-command-center.sh +358 -0
- package/scripts/rewrite-e2e-assets.mjs +23 -0
- package/scripts/validate-dashboard.sh +290 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: using-salesforce-data
|
|
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.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Salesforce Data Access
|
|
7
|
+
|
|
8
|
+
## When to Use
|
|
9
|
+
|
|
10
|
+
Use this skill when the user wants to:
|
|
11
|
+
|
|
12
|
+
- **Fetch or display Salesforce data** — Query records (Account, Contact, Opportunity, custom objects) to show in a component
|
|
13
|
+
- **Create, update, or delete records** — Perform mutations on Salesforce data
|
|
14
|
+
- **Add data fetching to a component** — Wire up a React component to Salesforce data
|
|
15
|
+
- **Call REST APIs** — Use Connect REST, Apex REST, or UI API endpoints
|
|
16
|
+
- **Explore the org schema** — Discover available objects, fields, or relationships
|
|
17
|
+
|
|
18
|
+
## Data SDK Requirement
|
|
19
|
+
|
|
20
|
+
> **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.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { createDataSDK, gql } from "@salesforce/sdk-data";
|
|
24
|
+
|
|
25
|
+
const sdk = await createDataSDK();
|
|
26
|
+
|
|
27
|
+
// GraphQL for record queries/mutations (PREFERRED)
|
|
28
|
+
const response = await sdk.graphql?.<ResponseType>(query, variables);
|
|
29
|
+
|
|
30
|
+
// REST for Connect REST, Apex REST, UI API (when GraphQL insufficient)
|
|
31
|
+
const res = await sdk.fetch?.("/services/apexrest/my-resource");
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Always use optional chaining** (`sdk.graphql?.()`, `sdk.fetch?.()`) — these methods may be undefined in some surfaces.
|
|
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
|
+
|
|
55
|
+
## Decision: GraphQL vs REST
|
|
56
|
+
|
|
57
|
+
| Need | Method | Example |
|
|
58
|
+
|------|--------|---------|
|
|
59
|
+
| Query/mutate records | `sdk.graphql` | Account, Contact, custom objects |
|
|
60
|
+
| Current user info | `sdk.graphql` | `uiapi { currentUser { Id Name { value } } }` |
|
|
61
|
+
| UI API record metadata | `sdk.fetch` | `/ui-api/records/{id}` |
|
|
62
|
+
| Connect REST | `sdk.fetch` | `/connect/file/upload/config` |
|
|
63
|
+
| Apex REST | `sdk.fetch` | `/services/apexrest/auth/login` |
|
|
64
|
+
| Einstein LLM | `sdk.fetch` | `/einstein/llm/prompt/generations` |
|
|
65
|
+
|
|
66
|
+
**GraphQL is preferred** for record operations. Use REST only when GraphQL doesn't cover the use case.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## GraphQL Workflow
|
|
71
|
+
|
|
72
|
+
### Step 1: Acquire Schema
|
|
73
|
+
|
|
74
|
+
The `schema.graphql` file (265K+ lines) is the source of truth. **Never open or parse it directly.**
|
|
75
|
+
|
|
76
|
+
1. Check if `schema.graphql` exists at the SFDX project root
|
|
77
|
+
2. If missing, run from the **webapp dir**: `npm run graphql:schema`
|
|
78
|
+
3. Custom objects appear only after metadata is deployed
|
|
79
|
+
|
|
80
|
+
### Step 2: Look Up Entity Schema
|
|
81
|
+
|
|
82
|
+
Map user intent to PascalCase names ("accounts" → `Account`), then **run the search script from the project root**:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
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
|
|
87
|
+
|
|
88
|
+
# Multiple entities at once
|
|
89
|
+
bash .a4drules/skills/using-salesforce-data/graphql-search.sh Account Contact Opportunity
|
|
90
|
+
```
|
|
91
|
+
|
|
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.
|
|
100
|
+
|
|
101
|
+
### Step 3: Generate Query
|
|
102
|
+
|
|
103
|
+
Use the templates below. Every field name **must** be verified from the script output in Step 2.
|
|
104
|
+
|
|
105
|
+
#### Read Query Template
|
|
106
|
+
|
|
107
|
+
```graphql
|
|
108
|
+
query GetAccounts {
|
|
109
|
+
uiapi {
|
|
110
|
+
query {
|
|
111
|
+
Account(where: { Industry: { eq: "Technology" } }, first: 10) {
|
|
112
|
+
edges {
|
|
113
|
+
node {
|
|
114
|
+
Id
|
|
115
|
+
Name @optional { value }
|
|
116
|
+
Industry @optional { value }
|
|
117
|
+
# Parent relationship
|
|
118
|
+
Owner @optional { Name { value } }
|
|
119
|
+
# Child relationship
|
|
120
|
+
Contacts @optional {
|
|
121
|
+
edges { node { Name @optional { value } } }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
**FLS Resilience**: Apply `@optional` to all record fields. The server omits inaccessible fields instead of failing. Consuming code must use optional chaining:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
const name = node.Name?.value ?? "";
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Mutation Template
|
|
138
|
+
|
|
139
|
+
```graphql
|
|
140
|
+
mutation CreateAccount($input: AccountCreateInput!) {
|
|
141
|
+
uiapi {
|
|
142
|
+
AccountCreate(input: $input) {
|
|
143
|
+
Record { Id Name { value } }
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Mutation constraints:**
|
|
150
|
+
- Create: Include required fields, only `createable` fields, no child relationships
|
|
151
|
+
- Update: Include `Id`, only `updateable` fields
|
|
152
|
+
- Delete: Include `Id` only
|
|
153
|
+
|
|
154
|
+
#### Object Metadata & Picklist Values
|
|
155
|
+
|
|
156
|
+
Use `uiapi { objectInfos(...) }` to fetch field metadata or picklist values. Pass **either** `apiNames` or `objectInfoInputs` — never both in the same query.
|
|
157
|
+
|
|
158
|
+
**Object metadata** (field labels, data types, CRUD flags):
|
|
159
|
+
|
|
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
|
+
`;
|
|
179
|
+
|
|
180
|
+
const sdk = await createDataSDK();
|
|
181
|
+
const response = await sdk.graphql?.(GET_OBJECT_INFO, { apiNames: ["Account"] });
|
|
182
|
+
const objectInfos = response?.data?.uiapi?.objectInfos ?? [];
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Picklist values** (use `objectInfoInputs` + `... on PicklistField` inline fragment):
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
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
|
+
`;
|
|
209
|
+
|
|
210
|
+
const response = await sdk.graphql?.(GET_PICKLIST_VALUES, {
|
|
211
|
+
objectInfoInputs: [{ objectApiName: "Account" }],
|
|
212
|
+
});
|
|
213
|
+
const fields = response?.data?.uiapi?.objectInfos?.[0]?.fields ?? [];
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Step 4: Validate & Test
|
|
217
|
+
|
|
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>
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Then fix the query using the exact names from the script output.
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## Webapp Integration (React)
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
import { createDataSDK, gql } from "@salesforce/sdk-data";
|
|
236
|
+
|
|
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
|
+
}
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
const sdk = await createDataSDK();
|
|
256
|
+
const response = await sdk.graphql?.(GET_ACCOUNTS);
|
|
257
|
+
|
|
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) ?? [];
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## REST API Patterns
|
|
268
|
+
|
|
269
|
+
Use `sdk.fetch` when GraphQL is insufficient. See the [Supported APIs](#supported-apis) table for the full allowlist.
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
declare const __SF_API_VERSION__: string;
|
|
273
|
+
const API_VERSION = typeof __SF_API_VERSION__ !== "undefined" ? __SF_API_VERSION__ : "65.0";
|
|
274
|
+
|
|
275
|
+
// Connect — file upload config
|
|
276
|
+
const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/connect/file/upload/config`);
|
|
277
|
+
|
|
278
|
+
// Apex REST (no version in path)
|
|
279
|
+
const res = await sdk.fetch?.("/services/apexrest/auth/login", {
|
|
280
|
+
method: "POST",
|
|
281
|
+
body: JSON.stringify({ email, password }),
|
|
282
|
+
headers: { "Content-Type": "application/json" },
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// UI API — record with metadata (prefer GraphQL for simple reads)
|
|
286
|
+
const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/ui-api/records/${recordId}`);
|
|
287
|
+
|
|
288
|
+
// Einstein LLM
|
|
289
|
+
const res = await sdk.fetch?.(`/services/data/v${API_VERSION}/einstein/llm/prompt/generations`, {
|
|
290
|
+
method: "POST",
|
|
291
|
+
body: JSON.stringify({ promptTextorId: prompt }),
|
|
292
|
+
});
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
**Current user**: Do not use Chatter (`/chatter/users/me`). Use GraphQL instead:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
const GET_CURRENT_USER = gql`
|
|
299
|
+
query CurrentUser {
|
|
300
|
+
uiapi { currentUser { Id Name { value } } }
|
|
301
|
+
}
|
|
302
|
+
`;
|
|
303
|
+
const response = await sdk.graphql?.(GET_CURRENT_USER);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Directory Structure
|
|
309
|
+
|
|
310
|
+
```
|
|
311
|
+
<project-root>/ ← SFDX project root
|
|
312
|
+
├── schema.graphql ← grep target (lives here)
|
|
313
|
+
├── sfdx-project.json
|
|
314
|
+
└── force-app/main/default/webapplications/<app-name>/ ← webapp dir
|
|
315
|
+
├── package.json ← npm scripts
|
|
316
|
+
└── src/
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
| Command | Run From | Why |
|
|
320
|
+
|---------|----------|-----|
|
|
321
|
+
| `npm run graphql:schema` | webapp dir | Script in webapp's package.json |
|
|
322
|
+
| `npx eslint <file>` | webapp dir | Reads eslint.config.js |
|
|
323
|
+
| `bash .a4drules/skills/using-salesforce-data/graphql-search.sh <Entity>` | project root | Schema lookup |
|
|
324
|
+
| `sf api request rest` | project root | Needs sfdx-project.json |
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## Quick Reference
|
|
329
|
+
|
|
330
|
+
### Schema Lookup (from project root)
|
|
331
|
+
|
|
332
|
+
Run the search script to get all relevant schema info in one step:
|
|
333
|
+
|
|
334
|
+
```bash
|
|
335
|
+
bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
| Script Output Section | Used For |
|
|
339
|
+
|-----------------------|----------|
|
|
340
|
+
| Type definition | Field names, parent/child relationships |
|
|
341
|
+
| Filter options | `where:` conditions |
|
|
342
|
+
| Sort options | `orderBy:` |
|
|
343
|
+
| CreateRepresentation | Create mutation field list |
|
|
344
|
+
| UpdateRepresentation | Update mutation field list |
|
|
345
|
+
|
|
346
|
+
### Error Categories
|
|
347
|
+
|
|
348
|
+
| Error Contains | Resolution |
|
|
349
|
+
|----------------|------------|
|
|
350
|
+
| `Cannot query field` | Field name is wrong — run `graphql-search.sh <Entity>` and use the exact name from the Type definition section |
|
|
351
|
+
| `Unknown type` | Type name is wrong — run `graphql-search.sh <Entity>` to confirm the correct PascalCase entity name |
|
|
352
|
+
| `Unknown argument` | Argument name is wrong — run `graphql-search.sh <Entity>` and check Filter or OrderBy sections |
|
|
353
|
+
| `invalid syntax` | Fix syntax per error message |
|
|
354
|
+
| `validation error` | Field name is wrong — run `graphql-search.sh <Entity>` to verify |
|
|
355
|
+
| `VariableTypeMismatch` | Correct argument type from schema |
|
|
356
|
+
| `invalid cross reference id` | Entity deleted — ask for valid Id |
|
|
357
|
+
|
|
358
|
+
### Checklist
|
|
359
|
+
|
|
360
|
+
- [ ] All field names verified via search script (Step 2)
|
|
361
|
+
- [ ] `@optional` applied to record fields (reads)
|
|
362
|
+
- [ ] Optional chaining in consuming code
|
|
363
|
+
- [ ] Lint passes: `npx eslint <file>`
|
|
@@ -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
|