@salesforce/afv-skills 1.1.0 → 1.3.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/package.json +6 -5
- package/skills/accessing-webapp-data/SKILL.md +178 -0
- package/skills/agentforce-development/SKILL.md +427 -0
- package/skills/agentforce-development/assets/README-legacy.md +89 -0
- package/skills/agentforce-development/assets/agent-spec-template.md +90 -0
- package/skills/agentforce-development/assets/agents/README.md +45 -0
- package/skills/agentforce-development/assets/agents/hello-world.agent +60 -0
- package/skills/agentforce-development/assets/agents/multi-topic.agent +105 -0
- package/skills/agentforce-development/assets/agents/production-faq.agent +101 -0
- package/skills/agentforce-development/assets/agents/production-faq.bundle-meta.xml +4 -0
- package/skills/agentforce-development/assets/agents/simple-qa.agent +72 -0
- package/skills/agentforce-development/assets/apex/models-api-queueable.cls +225 -0
- package/skills/agentforce-development/assets/bundle-meta.xml +23 -0
- package/skills/agentforce-development/assets/components/apex-action.agent +52 -0
- package/skills/agentforce-development/assets/components/error-handling.agent +58 -0
- package/skills/agentforce-development/assets/components/escalation-setup.agent +169 -0
- package/skills/agentforce-development/assets/components/flow-action.agent +66 -0
- package/skills/agentforce-development/assets/components/n-ary-conditions.agent +110 -0
- package/skills/agentforce-development/assets/components/topic-with-actions.agent +40 -0
- package/skills/agentforce-development/assets/deterministic-routing.agent +166 -0
- package/skills/agentforce-development/assets/escalation-pattern.agent +209 -0
- package/skills/agentforce-development/assets/flow-action-lookup.agent +115 -0
- package/skills/agentforce-development/assets/hub-and-spoke.agent +104 -0
- package/skills/agentforce-development/assets/invocable-apex-template.cls +187 -0
- package/skills/agentforce-development/assets/local-info-agent-annotated.agent +355 -0
- package/skills/agentforce-development/assets/metadata/basic-prompt-template.promptTemplate-meta.xml +109 -0
- package/skills/agentforce-development/assets/metadata/genai-function-apex.xml +92 -0
- package/skills/agentforce-development/assets/metadata/genai-function-flow.xml +57 -0
- package/skills/agentforce-development/assets/metadata/genai-plugin.xml +72 -0
- package/skills/agentforce-development/assets/metadata/http-callout-flow.flow-meta.xml +348 -0
- package/skills/agentforce-development/assets/metadata/record-grounded-prompt.promptTemplate-meta.xml +136 -0
- package/skills/agentforce-development/assets/minimal-starter.agent +42 -0
- package/skills/agentforce-development/assets/patterns/README.md +254 -0
- package/skills/agentforce-development/assets/patterns/action-callbacks.agent +178 -0
- package/skills/agentforce-development/assets/patterns/advanced-input-bindings.agent +141 -0
- package/skills/agentforce-development/assets/patterns/bidirectional-routing.agent +156 -0
- package/skills/agentforce-development/assets/patterns/critical-input-collection.agent +244 -0
- package/skills/agentforce-development/assets/patterns/delegation-routing.agent +89 -0
- package/skills/agentforce-development/assets/patterns/lifecycle-events.agent +127 -0
- package/skills/agentforce-development/assets/patterns/llm-controlled-actions.agent +184 -0
- package/skills/agentforce-development/assets/patterns/multi-step-workflow.agent +282 -0
- package/skills/agentforce-development/assets/patterns/open-gate-routing.agent +286 -0
- package/skills/agentforce-development/assets/patterns/procedural-instructions.agent +273 -0
- package/skills/agentforce-development/assets/patterns/prompt-template-action.agent +188 -0
- package/skills/agentforce-development/assets/patterns/system-instruction-overrides.agent +293 -0
- package/skills/agentforce-development/assets/prompt-rag-search.agent +131 -0
- package/skills/agentforce-development/assets/template-multi-topic.agent +160 -0
- package/skills/agentforce-development/assets/template-single-topic.agent +81 -0
- package/skills/agentforce-development/assets/verification-gate.agent +208 -0
- package/skills/agentforce-development/references/action-prompt-templates.md +164 -0
- package/skills/agentforce-development/references/actions-reference.md +592 -0
- package/skills/agentforce-development/references/agent-access-guide.md +72 -0
- package/skills/agentforce-development/references/agent-design-and-spec-creation.md +1010 -0
- package/skills/agentforce-development/references/agent-metadata-and-lifecycle.md +575 -0
- package/skills/agentforce-development/references/agent-script-core-language.md +1218 -0
- package/skills/agentforce-development/references/agent-topic-map-diagrams.md +323 -0
- package/skills/agentforce-development/references/agent-user-setup.md +526 -0
- package/skills/agentforce-development/references/agent-validation-and-debugging.md +803 -0
- package/skills/agentforce-development/references/known-issues.md +353 -0
- package/skills/agentforce-development/references/minimal-examples.md +67 -0
- package/skills/agentforce-development/references/production-gotchas.md +279 -0
- package/skills/agentforce-development/references/salesforce-cli-for-agents.md +393 -0
- package/skills/agentforce-development/references/version-history.md +23 -0
- package/skills/building-webapp-data-visualization/SKILL.md +72 -0
- package/skills/building-webapp-data-visualization/implementation/bar-line-chart.md +316 -0
- package/skills/building-webapp-data-visualization/implementation/dashboard-layout.md +189 -0
- package/skills/building-webapp-data-visualization/implementation/donut-chart.md +181 -0
- package/skills/building-webapp-data-visualization/implementation/stat-card.md +150 -0
- package/skills/building-webapp-react-components/SKILL.md +96 -0
- package/skills/building-webapp-react-components/implementation/component.md +78 -0
- package/skills/building-webapp-react-components/implementation/header-footer.md +132 -0
- package/skills/building-webapp-react-components/implementation/page.md +93 -0
- package/skills/configuring-webapp-csp-trusted-sites/SKILL.md +90 -0
- package/skills/configuring-webapp-csp-trusted-sites/implementation/metadata-format.md +281 -0
- package/skills/configuring-webapp-metadata/SKILL.md +158 -0
- package/skills/creating-webapp/SKILL.md +141 -0
- package/skills/deploying-webapp-to-salesforce/SKILL.md +229 -0
- package/skills/exploring-webapp-graphql-schema/SKILL.md +149 -0
- package/skills/fetching-webapp-rest-api/SKILL.md +167 -0
- package/skills/{salesforce-custom-application → generating-custom-application}/SKILL.md +2 -4
- package/skills/{salesforce-custom-field → generating-custom-field}/SKILL.md +1 -5
- package/skills/{salesforce-custom-lightning-type → generating-custom-lightning-type}/SKILL.md +36 -2
- package/skills/{salesforce-custom-object → generating-custom-object}/SKILL.md +1 -1
- package/skills/generating-custom-tab/SKILL.md +154 -0
- package/skills/generating-experience-lwr-site/SKILL.md +196 -0
- package/skills/generating-experience-lwr-site/docs/bootstrap-template-byo-lwr.md +224 -0
- package/skills/generating-experience-lwr-site/docs/configure-content-brandingSet.md +131 -0
- package/skills/generating-experience-lwr-site/docs/configure-content-route.md +232 -0
- package/skills/generating-experience-lwr-site/docs/configure-content-themeLayout.md +141 -0
- package/skills/generating-experience-lwr-site/docs/configure-content-view.md +233 -0
- package/skills/generating-experience-lwr-site/docs/configure-guest-sharing-rules.md +42 -0
- package/skills/generating-experience-lwr-site/docs/handle-component-and-region-ids.md +27 -0
- package/skills/generating-experience-lwr-site/docs/handle-ui-components.md +215 -0
- package/skills/generating-experience-react-site/SKILL.md +67 -0
- package/skills/generating-experience-react-site/docs/configure-metadata-custom-site.md +41 -0
- package/skills/generating-experience-react-site/docs/configure-metadata-digital-experience-bundle.md +17 -0
- package/skills/generating-experience-react-site/docs/configure-metadata-digital-experience-config.md +21 -0
- package/skills/generating-experience-react-site/docs/configure-metadata-digital-experience.md +38 -0
- package/skills/generating-experience-react-site/docs/configure-metadata-network.md +72 -0
- package/skills/{salesforce-flexipage → generating-flexipage}/SKILL.md +86 -9
- package/skills/{salesforce-flow → generating-flow}/SKILL.md +3 -3
- package/skills/generating-fragment/SKILL.md +117 -0
- package/skills/generating-lightning-app/SKILL.md +423 -0
- package/skills/{salesforce-list-view → generating-list-view}/SKILL.md +1 -1
- package/skills/generating-permission-set/SKILL.md +174 -0
- package/skills/{salesforce-validation-rule → generating-validation-rule}/SKILL.md +1 -1
- package/skills/generating-webapp-graphql-mutation-query/SKILL.md +258 -0
- package/skills/generating-webapp-graphql-read-query/SKILL.md +253 -0
- package/skills/implementing-webapp-file-upload/SKILL.md +396 -0
- package/skills/installing-webapp-features/SKILL.md +210 -0
- package/skills/managing-webapp-agentforce-conversation-client/SKILL.md +186 -0
- package/skills/managing-webapp-agentforce-conversation-client/references/constraints.md +134 -0
- package/skills/managing-webapp-agentforce-conversation-client/references/examples.md +132 -0
- package/skills/managing-webapp-agentforce-conversation-client/references/style-tokens.md +101 -0
- package/skills/managing-webapp-agentforce-conversation-client/references/troubleshooting.md +57 -0
- package/skills/switching-org/SKILL.md +28 -0
- package/skills/using-webapp-graphql/SKILL.md +324 -0
- package/skills/using-webapp-graphql/shared-schema.graphqls +1150 -0
- package/skills/apex-class/SKILL.md +0 -253
- package/skills/apex-class/examples/AccountDeduplicationBatch.cls +0 -148
- package/skills/apex-class/examples/AccountSelector.cls +0 -193
- package/skills/apex-class/examples/AccountService.cls +0 -201
- package/skills/apex-class/templates/abstract.cls +0 -128
- package/skills/apex-class/templates/batch.cls +0 -125
- package/skills/apex-class/templates/domain.cls +0 -102
- package/skills/apex-class/templates/dto.cls +0 -108
- package/skills/apex-class/templates/exception.cls +0 -51
- package/skills/apex-class/templates/interface.cls +0 -25
- package/skills/apex-class/templates/queueable.cls +0 -92
- package/skills/apex-class/templates/schedulable.cls +0 -75
- package/skills/apex-class/templates/selector.cls +0 -92
- package/skills/apex-class/templates/service.cls +0 -69
- package/skills/apex-class/templates/utility.cls +0 -97
- package/skills/apex-test-class/SKILL.md +0 -101
- package/skills/apex-test-class/references/assertion-patterns.md +0 -209
- package/skills/apex-test-class/references/async-testing.md +0 -276
- package/skills/apex-test-class/references/mocking-patterns.md +0 -219
- package/skills/apex-test-class/references/test-data-factory.md +0 -176
- package/skills/deployment-readiness-check/SKILL.md +0 -257
- package/skills/deployment-readiness-check/assets/deployment_checklist.md +0 -286
- package/skills/deployment-readiness-check/references/rollback_procedures.md +0 -308
- package/skills/deployment-readiness-check/scripts/check_metadata.sh +0 -207
- package/skills/salesforce-custom-tab/SKILL.md +0 -78
- package/skills/salesforce-experience-site/SKILL.md +0 -178
- package/skills/salesforce-fragment/SKILL.md +0 -42
- package/skills/salesforce-lightning-app-build/SKILL.md +0 -254
- package/skills/salesforce-web-app-creating-records/SKILL.md +0 -84
- package/skills/salesforce-web-app-feature/SKILL.md +0 -70
- package/skills/salesforce-web-app-list-and-create-records/SKILL.md +0 -36
- package/skills/salesforce-web-application/SKILL.md +0 -34
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: generating-webapp-graphql-read-query
|
|
3
|
+
description: Generate Salesforce GraphQL read queries. Use when the query to generate is a read query. Schema exploration must complete first — invoke exploring-graphql-schema first.
|
|
4
|
+
paths:
|
|
5
|
+
- "**/*.ts"
|
|
6
|
+
- "**/*.tsx"
|
|
7
|
+
- "**/*.graphql"
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# Salesforce GraphQL Read Query Generation
|
|
11
|
+
|
|
12
|
+
**Triggering conditions**
|
|
13
|
+
|
|
14
|
+
1. Only if the schema exploration phase completed successfully (invoke `exploring-graphql-schema` first)
|
|
15
|
+
2. Only if the query to generate is a read query
|
|
16
|
+
|
|
17
|
+
## Schema Access Policy
|
|
18
|
+
|
|
19
|
+
> ⚠️ **GREP ONLY** — During query generation you may need to verify field names, types, or relationships. All schema lookups **MUST** use the grep-only commands defined in the `exploring-graphql-schema` skill. Do NOT open, read, stream, or parse `./schema.graphql` with any tool other than grep.
|
|
20
|
+
|
|
21
|
+
## Field-Level Security and @optional
|
|
22
|
+
|
|
23
|
+
Field-level security (FLS) restricts which fields different users can see. Use the `@optional` directive on Salesforce record fields when possible. The server omits the field when the user lacks access, allowing the query to succeed instead of failing. Apply `@optional` to scalar fields, value-type fields (e.g. `Name { value }`), parent relationships, and child relationships. Available in API v65.0+.
|
|
24
|
+
|
|
25
|
+
**Consuming code must defend against missing fields.** When a field is omitted due to FLS, it will be `undefined` (or absent) in the response. Use optional chaining (`?.`), nullish coalescing (`??`), and explicit null/undefined checks when reading query results. Never assume an optional field is present — otherwise the app may crash or behave incorrectly for users without field access.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// ✅ Defend against missing fields
|
|
29
|
+
const name = node.Name?.value ?? '';
|
|
30
|
+
const relatedName = node.RelationshipName?.Name?.value ?? 'N/A';
|
|
31
|
+
|
|
32
|
+
// ❌ Unsafe — will throw if field omitted due to FLS
|
|
33
|
+
const name = node.Name.value;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Your Role
|
|
37
|
+
|
|
38
|
+
You are a GraphQL expert. Generate Salesforce-compatible read queries. Schema exploration must complete first. If the schema exploration has not been executed yet, you **MUST** run the full exploration workflow from the `exploring-graphql-schema` skill first, then return here for read query generation.
|
|
39
|
+
|
|
40
|
+
## Read Query Generation Workflow
|
|
41
|
+
|
|
42
|
+
Strictly follow the rules below when generating the GraphQL read query:
|
|
43
|
+
|
|
44
|
+
1. **No Proliferation** - Only generate for the explicitly requested fields, nothing else. Do NOT add fields the user did not ask for.
|
|
45
|
+
2. **Unique Query** - Leverage child relationships to query entities in one single query
|
|
46
|
+
3. **Navigate Entities** - Always use `relationshipName` to access reference fields and child entities
|
|
47
|
+
1. **Exception** - if the `relationshipName` field is null, you can't navigate the related entity, and will have to return the `Id` itself
|
|
48
|
+
4. **Leverage Fragments** - Generate one fragment per possible type on polymorphic fields (field with `dataType="REFERENCE"` and more than one entry in `referenceToInfos` introspection attribute)
|
|
49
|
+
5. **Type Consistency** - Make sure variables used as query arguments and their related fields share the same GraphQL type. Verify types against grep output from the schema — do not assume types
|
|
50
|
+
6. **Type Enforcement** - Make sure to leverage field type information from introspection and GraphQL schema to generate field access
|
|
51
|
+
7. **Field Name Validation** - Every field name in the generated query **MUST** match a field confirmed via grep lookup in the schema. Do NOT guess or assume field names exist
|
|
52
|
+
8. **@optional for FLS** - Apply `@optional` on all Salesforce record fields when possible (see [Field-Level Security and @optional](#field-level-security-and-optional)). This lets the query succeed when the user lacks field-level access; the server omits inaccessible fields instead of failing
|
|
53
|
+
9. **Consuming code defense** - When generating or modifying code that consumes read query results, defend against missing fields (see [Field-Level Security and @optional](#field-level-security-and-optional)). Use optional chaining, nullish coalescing, and null/undefined checks — never assume optional fields are present
|
|
54
|
+
10. **Semi and anti joins** - Use the semi-join or anti-join templates to filter an entity with conditions on child entities
|
|
55
|
+
11. **Query Generation** - Use the [template](#read-query-template) to generate the query
|
|
56
|
+
12. **Output Format** - Use the [standalone](#read-standalone-default-output-format---clean-code-only)
|
|
57
|
+
13. **Lint Validation** - After writing the query to a file, run `npx eslint <file>` from the webapp dir to validate it against the schema. Fix any reported errors before proceeding. See [Lint Validation](#lint-validation) for details
|
|
58
|
+
14. **Test the Query** - Use the [Generated Read Query Testing](#generated-read-query-testing) workflow to test the generated query
|
|
59
|
+
1. **Report First** - Always output the generated query in the proper output format BEFORE initiating any test
|
|
60
|
+
|
|
61
|
+
## Read Query Template
|
|
62
|
+
|
|
63
|
+
```graphql
|
|
64
|
+
query QueryName {
|
|
65
|
+
uiapi {
|
|
66
|
+
query {
|
|
67
|
+
EntityName(
|
|
68
|
+
# conditions here
|
|
69
|
+
) {
|
|
70
|
+
edges {
|
|
71
|
+
node {
|
|
72
|
+
# Direct fields — use @optional for FLS resilience
|
|
73
|
+
FieldName @optional { value }
|
|
74
|
+
|
|
75
|
+
# Non-polymorphic reference (single type)
|
|
76
|
+
RelationshipName @optional {
|
|
77
|
+
Id
|
|
78
|
+
Name { value }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
# Polymorphic reference (multiple types)
|
|
82
|
+
PolymorphicRelationshipName @optional {
|
|
83
|
+
...TypeAInfo
|
|
84
|
+
...TypeBInfo
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Child relationship (subquery)
|
|
88
|
+
RelationshipName @optional (
|
|
89
|
+
# conditions here
|
|
90
|
+
) {
|
|
91
|
+
edges {
|
|
92
|
+
node {
|
|
93
|
+
# fields
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fragment TypeAInfo on TypeA {
|
|
105
|
+
Id
|
|
106
|
+
SpecificFieldA @optional { value }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fragment TypeBInfo on TypeB {
|
|
110
|
+
Id
|
|
111
|
+
SpecificFieldB @optional { value }
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Semi-Join and Anti-Join Condition Template
|
|
116
|
+
|
|
117
|
+
Semi-joins (resp. anti-joins) condition leverage parent-child relationships and allow filtering the parent entity using a condition on child entities.
|
|
118
|
+
This is a standard `where` condition, on the parent entity's `Id`, expressed using the `inq` (resp. `ninq`, i.e. not `inq`) operator. This operator accepts two attributes:
|
|
119
|
+
|
|
120
|
+
- The child entity camelcase name to apply the condition on, with a value expressing the condition
|
|
121
|
+
- The field name on the child entity containing the parent entity `Id`, which is the `fieldName` from the `childRelationships` information for the child entity
|
|
122
|
+
- If the only condition is related child entity existence, you can use an `Id: { ne: null }` condition
|
|
123
|
+
|
|
124
|
+
### Semi-Join Example - ParentEntity with at least one Matching ChildEntity
|
|
125
|
+
|
|
126
|
+
```graphql
|
|
127
|
+
query testSemiJoin {
|
|
128
|
+
uiapi {
|
|
129
|
+
query {
|
|
130
|
+
ParentEntity(
|
|
131
|
+
where: {
|
|
132
|
+
Id: {
|
|
133
|
+
inq: {
|
|
134
|
+
ChildEntity: {
|
|
135
|
+
# standard conditions here
|
|
136
|
+
Name: { like: "test%" }
|
|
137
|
+
Type: { eq: "some value" }
|
|
138
|
+
}
|
|
139
|
+
ApiName: "parentIdFieldInChild"
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
) {
|
|
144
|
+
edges {
|
|
145
|
+
node {
|
|
146
|
+
Id
|
|
147
|
+
Name @optional {
|
|
148
|
+
value
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Anti-Join Example - ParentEntity with no Matching ChildEntity
|
|
159
|
+
|
|
160
|
+
Same example as the [Semi-Join Example](#semi-join-example---parententity-with-at-least-one-matching-childentity), but replacing the `inq` operator by the `ninq` one.
|
|
161
|
+
|
|
162
|
+
## Read Standalone (Default) Output Format - CLEAN CODE ONLY
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
const QUERY_NAME = `
|
|
166
|
+
query GetData {
|
|
167
|
+
# query here
|
|
168
|
+
}
|
|
169
|
+
`;
|
|
170
|
+
|
|
171
|
+
const QUERY_VARIABLES = {
|
|
172
|
+
// variables here
|
|
173
|
+
};
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**❌ FORBIDDEN — Do NOT include any of the following:**
|
|
177
|
+
|
|
178
|
+
- Explanatory comments about the query (inline or surrounding)
|
|
179
|
+
- Field descriptions or annotations
|
|
180
|
+
- Additional text about what the query does
|
|
181
|
+
- Workflow step descriptions or summaries
|
|
182
|
+
- Comments like `// fetches...`, `// returns...`, `/* ... */`
|
|
183
|
+
|
|
184
|
+
**✅ ONLY output:**
|
|
185
|
+
|
|
186
|
+
- The raw query string constant
|
|
187
|
+
- The variables object constant
|
|
188
|
+
- Nothing else — no imports, no exports, no wrapper functions
|
|
189
|
+
|
|
190
|
+
## Lint Validation
|
|
191
|
+
|
|
192
|
+
After writing the generated query into a source file, validate it against the schema using the project's GraphQL ESLint setup:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Run from webapp dir (force-app/main/default/webapplications/<app-name>/)
|
|
196
|
+
npx eslint <path-to-file-containing-query>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**How it works:** The ESLint config uses `@graphql-eslint/eslint-plugin` with its `processor`, which extracts GraphQL operations from `gql` template literals in `.ts`/`.tsx` files and validates the extracted `.graphql` virtual files against `schema.graphql`.
|
|
200
|
+
|
|
201
|
+
**Rules enforced:** `no-anonymous-operations`, `no-duplicate-fields`, `known-fragment-names`, `no-undefined-variables`, `no-unused-variables`
|
|
202
|
+
|
|
203
|
+
**On failure:** Fix the reported issues, re-run `npx eslint <file>` until clean, then proceed to testing.
|
|
204
|
+
|
|
205
|
+
> ⚠️ **Prerequisites**: The `schema.graphql` file must exist (invoke `exploring-graphql-schema` first) and project dependencies must be installed (`npm install`).
|
|
206
|
+
|
|
207
|
+
## Generated Read Query Testing
|
|
208
|
+
|
|
209
|
+
**Triggering conditions** — **ALL conditions must be true:**
|
|
210
|
+
|
|
211
|
+
1. The [Read Query Generation Workflow](#read-query-generation-workflow) completed with status `SUCCESS` and you have a generated query
|
|
212
|
+
2. The query is a read query
|
|
213
|
+
3. A non-manual method was used during schema exploration to retrieve introspection data
|
|
214
|
+
|
|
215
|
+
**Workflow**
|
|
216
|
+
|
|
217
|
+
1. **Report Step** - State the exact method you will use to test (e.g., `sf api request graphql` from the **project root**, Connect API, etc.) — this **MUST** match the method used during schema exploration
|
|
218
|
+
2. **Interactive Step** - Ask the user whether they want you to test the query using the proposed method
|
|
219
|
+
1. **STOP and WAIT** for the user's answer. Do NOT proceed until the user responds. Do NOT assume consent.
|
|
220
|
+
3. **Test Query** - Only if the user explicitly agrees:
|
|
221
|
+
1. Use `sf api request rest` to POST the query to the GraphQL endpoint:
|
|
222
|
+
```bash
|
|
223
|
+
sf api request rest /services/data/v65.0/graphql \
|
|
224
|
+
--method POST \
|
|
225
|
+
--body '{"query":"query GetData { uiapi { query { EntityName { edges { node { Id } } } } } }"}'
|
|
226
|
+
```
|
|
227
|
+
2. Replace `v65.0` with the API version of the target org
|
|
228
|
+
3. Replace the `query` value with the generated read query string
|
|
229
|
+
4. If the query uses variables, include them in the JSON body as a `variables` key
|
|
230
|
+
5. Report the result as `SUCCESS` if the query executed without error, or `FAILED` if errors were returned
|
|
231
|
+
6. An empty result set with no errors is `SUCCESS` — the query is valid, the org simply has no matching data
|
|
232
|
+
4. **Remediation Step** - If status is `FAILED`, use the [`FAILED` status handling workflows](#failed-status-handling-workflow)
|
|
233
|
+
|
|
234
|
+
### `FAILED` Status Handling Workflow
|
|
235
|
+
|
|
236
|
+
The query is invalid:
|
|
237
|
+
|
|
238
|
+
1. **Error Analysis** - Parse and categorize the specific error messages
|
|
239
|
+
2. **Root Cause Identification** - Use error message to identify the root cause:
|
|
240
|
+
- **Syntax** - Error contains `invalid syntax`
|
|
241
|
+
- **Validation** - Error contains `validation error`
|
|
242
|
+
- **Type** - Error contains `VariableTypeMismatch` or `UnknownType`
|
|
243
|
+
3. **Targeted Resolution** - Depending on the root cause categorization
|
|
244
|
+
- **Syntax** - Update the query using the error message information to fix the syntax errors
|
|
245
|
+
- **Validation** - The field name is most probably invalid. Re-run the relevant grep command from the `exploring-graphql-schema` skill to verify the correct field name. If still unclear, ask the user for clarification and **STOP and WAIT** for their answer
|
|
246
|
+
- **Type** - Use the error details and re-verify the type via grep lookup in the schema. Correct the argument type and adjust variables accordingly
|
|
247
|
+
4. **Test Again** - Resume the [query testing workflow](#generated-read-query-testing) with the updated query (increment and track attempt counter)
|
|
248
|
+
5. **Escalation Path** - If targeted resolution fails after 2 attempts, ask for additional details and restart the entire GraphQL workflow from the `exploring-graphql-schema` skill
|
|
249
|
+
|
|
250
|
+
## Related Skills
|
|
251
|
+
|
|
252
|
+
- Schema exploration: `exploring-graphql-schema` (must complete first)
|
|
253
|
+
- Mutation generation: `generating-graphql-mutation-query`
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: implementing-webapp-file-upload
|
|
3
|
+
description: Add file upload functionality to React webapps with progress tracking and Salesforce ContentVersion integration. Use when the user wants to upload files, attach documents, handle file input, create file dropzones, track upload progress, or link files to Salesforce records. This feature provides programmatic APIs ONLY — no components or hooks are exported. Build your own custom UI using the upload() API. ALWAYS use this feature instead of building file upload from scratch with FormData or XHR.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# File Upload API (workflow)
|
|
7
|
+
|
|
8
|
+
When the user wants file upload functionality in a React webapp, follow this workflow. This feature provides **APIs only** — you must build the UI components yourself using the provided APIs.
|
|
9
|
+
|
|
10
|
+
## CRITICAL: This is an API-only package
|
|
11
|
+
|
|
12
|
+
The package exports **programmatic APIs**, not React components or hooks. You will:
|
|
13
|
+
|
|
14
|
+
- Use the `upload()` function to handle file uploads with progress tracking
|
|
15
|
+
- Build your own custom UI (file input, dropzone, progress bars, etc.)
|
|
16
|
+
- Track upload progress through the `onProgress` callback
|
|
17
|
+
|
|
18
|
+
**Do NOT:**
|
|
19
|
+
|
|
20
|
+
- Expect pre-built components like `<FileUpload />` — they are not exported
|
|
21
|
+
- Try to import React hooks like `useFileUpload` — they are not exported
|
|
22
|
+
- Look for dropzone components — they are not exported
|
|
23
|
+
|
|
24
|
+
The source code contains reference components for demonstration, but they are **not available** as imports. Use them as examples to build your own UI.
|
|
25
|
+
|
|
26
|
+
## 1. Install the package
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @salesforce/webapp-template-feature-react-file-upload-experimental
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Dependencies are automatically installed:
|
|
33
|
+
|
|
34
|
+
- `@salesforce/webapp-experimental` (API client)
|
|
35
|
+
- `@salesforce/sdk-data` (data SDK)
|
|
36
|
+
|
|
37
|
+
## 2. Understand the three upload patterns
|
|
38
|
+
|
|
39
|
+
### Pattern A: Basic upload (no record linking)
|
|
40
|
+
|
|
41
|
+
Upload files to Salesforce and get back `contentBodyId` for each file. No ContentVersion record is created.
|
|
42
|
+
|
|
43
|
+
**When to use:**
|
|
44
|
+
|
|
45
|
+
- User wants to upload files first, then create/link them to a record later
|
|
46
|
+
- Building a multi-step form where the record doesn't exist yet
|
|
47
|
+
- Deferred record linking scenarios
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
import { upload } from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
51
|
+
|
|
52
|
+
const results = await upload({
|
|
53
|
+
files: [file1, file2],
|
|
54
|
+
onProgress: (progress) => {
|
|
55
|
+
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// results[0].contentBodyId: "069..." (always available)
|
|
60
|
+
// results[0].contentVersionId: undefined (no record linked)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Pattern B: Upload with immediate record linking
|
|
64
|
+
|
|
65
|
+
Upload files and immediately link them to an existing Salesforce record by creating ContentVersion records.
|
|
66
|
+
|
|
67
|
+
**When to use:**
|
|
68
|
+
|
|
69
|
+
- Record already exists (Account, Opportunity, Case, etc.)
|
|
70
|
+
- User wants files immediately attached to the record
|
|
71
|
+
- Direct upload-and-attach scenarios
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
import { upload } from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
75
|
+
|
|
76
|
+
const results = await upload({
|
|
77
|
+
files: [file1, file2],
|
|
78
|
+
recordId: "001xx000000yyyy", // Existing record ID
|
|
79
|
+
onProgress: (progress) => {
|
|
80
|
+
console.log(`${progress.fileName}: ${progress.status} - ${progress.progress}%`);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// results[0].contentBodyId: "069..." (always available)
|
|
85
|
+
// results[0].contentVersionId: "068..." (linked to record)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Pattern C: Deferred record linking (record creation flow)
|
|
89
|
+
|
|
90
|
+
Upload files without a record, then link them after the record is created.
|
|
91
|
+
|
|
92
|
+
**When to use:**
|
|
93
|
+
|
|
94
|
+
- Building a "create record with attachments" form
|
|
95
|
+
- Record doesn't exist until form submission
|
|
96
|
+
- Need to upload files before knowing the final record ID
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
import {
|
|
100
|
+
upload,
|
|
101
|
+
createContentVersion,
|
|
102
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
103
|
+
|
|
104
|
+
// Step 1: Upload files (no recordId)
|
|
105
|
+
const uploadResults = await upload({
|
|
106
|
+
files: [file1, file2],
|
|
107
|
+
onProgress: (progress) => console.log(progress),
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// Step 2: Create the record
|
|
111
|
+
const newRecordId = await createRecord(formData);
|
|
112
|
+
|
|
113
|
+
// Step 3: Link uploaded files to the new record
|
|
114
|
+
for (const file of uploadResults) {
|
|
115
|
+
const contentVersionId = await createContentVersion(
|
|
116
|
+
new File([""], file.fileName),
|
|
117
|
+
file.contentBodyId,
|
|
118
|
+
newRecordId,
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 3. Build your custom UI
|
|
124
|
+
|
|
125
|
+
The package provides the backend — you build the frontend. Here's a minimal example:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
import {
|
|
129
|
+
upload,
|
|
130
|
+
type FileUploadProgress,
|
|
131
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
132
|
+
import { useState } from "react";
|
|
133
|
+
|
|
134
|
+
function CustomFileUpload({ recordId }: { recordId?: string }) {
|
|
135
|
+
const [progress, setProgress] = useState<Map<string, FileUploadProgress>>(new Map());
|
|
136
|
+
|
|
137
|
+
const handleFileSelect = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
138
|
+
const files = Array.from(event.target.files || []);
|
|
139
|
+
|
|
140
|
+
await upload({
|
|
141
|
+
files,
|
|
142
|
+
recordId,
|
|
143
|
+
onProgress: (fileProgress) => {
|
|
144
|
+
setProgress((prev) => new Map(prev).set(fileProgress.fileName, fileProgress));
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div>
|
|
151
|
+
<input type="file" multiple onChange={handleFileSelect} />
|
|
152
|
+
|
|
153
|
+
{Array.from(progress.entries()).map(([fileName, fileProgress]) => (
|
|
154
|
+
<div key={fileName}>
|
|
155
|
+
{fileName}: {fileProgress.status} - {fileProgress.progress}%
|
|
156
|
+
{fileProgress.error && <span>Error: {fileProgress.error}</span>}
|
|
157
|
+
</div>
|
|
158
|
+
))}
|
|
159
|
+
</div>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 4. Track upload progress
|
|
165
|
+
|
|
166
|
+
The `onProgress` callback fires multiple times for each file as it moves through stages:
|
|
167
|
+
|
|
168
|
+
| Status | When | Progress Value |
|
|
169
|
+
| -------------- | ---------------------------------------------- | -------------------- |
|
|
170
|
+
| `"pending"` | File queued for upload | `0` |
|
|
171
|
+
| `"uploading"` | Upload in progress (XHR) | `0-100` (percentage) |
|
|
172
|
+
| `"processing"` | Creating ContentVersion (if recordId provided) | `0` |
|
|
173
|
+
| `"success"` | Upload complete | `100` |
|
|
174
|
+
| `"error"` | Upload failed | `0` |
|
|
175
|
+
|
|
176
|
+
**Always provide visual feedback:**
|
|
177
|
+
|
|
178
|
+
- Show file name
|
|
179
|
+
- Display current status
|
|
180
|
+
- Render progress bar for "uploading" status
|
|
181
|
+
- Show error message if status is "error"
|
|
182
|
+
|
|
183
|
+
## 5. Cancel uploads (optional)
|
|
184
|
+
|
|
185
|
+
Use an `AbortController` to allow users to cancel uploads:
|
|
186
|
+
|
|
187
|
+
```tsx
|
|
188
|
+
const abortController = new AbortController();
|
|
189
|
+
|
|
190
|
+
const handleUpload = async (files: File[]) => {
|
|
191
|
+
try {
|
|
192
|
+
await upload({
|
|
193
|
+
files,
|
|
194
|
+
signal: abortController.signal,
|
|
195
|
+
onProgress: (progress) => console.log(progress),
|
|
196
|
+
});
|
|
197
|
+
} catch (error) {
|
|
198
|
+
console.error("Upload cancelled or failed:", error);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
const cancelUpload = () => {
|
|
203
|
+
abortController.abort();
|
|
204
|
+
};
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## 6. Link to current user (special case)
|
|
208
|
+
|
|
209
|
+
If the user wants to upload files to their own profile or personal library:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
import {
|
|
213
|
+
upload,
|
|
214
|
+
getCurrentUserId,
|
|
215
|
+
} from "@salesforce/webapp-template-feature-react-file-upload-experimental";
|
|
216
|
+
|
|
217
|
+
const userId = await getCurrentUserId();
|
|
218
|
+
await upload({ files, recordId: userId });
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## API Reference
|
|
222
|
+
|
|
223
|
+
### upload(options)
|
|
224
|
+
|
|
225
|
+
Main upload API that handles complete flow with progress tracking.
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
interface UploadOptions {
|
|
229
|
+
files: File[];
|
|
230
|
+
recordId?: string | null; // If provided, creates ContentVersion
|
|
231
|
+
onProgress?: (progress: FileUploadProgress) => void;
|
|
232
|
+
signal?: AbortSignal; // Optional cancellation
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
interface FileUploadProgress {
|
|
236
|
+
fileName: string;
|
|
237
|
+
status: "pending" | "uploading" | "processing" | "success" | "error";
|
|
238
|
+
progress: number; // 0-100 for uploading, 0 for other states
|
|
239
|
+
error?: string;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface FileUploadResult {
|
|
243
|
+
fileName: string;
|
|
244
|
+
size: number;
|
|
245
|
+
contentBodyId: string; // Always available
|
|
246
|
+
contentVersionId?: string; // Only if recordId was provided
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**Returns:** `Promise<FileUploadResult[]>`
|
|
251
|
+
|
|
252
|
+
### createContentVersion(file, contentBodyId, recordId)
|
|
253
|
+
|
|
254
|
+
Manually create a ContentVersion record from a previously uploaded file.
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
async function createContentVersion(
|
|
258
|
+
file: File,
|
|
259
|
+
contentBodyId: string,
|
|
260
|
+
recordId: string,
|
|
261
|
+
): Promise<string | undefined>;
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**Parameters:**
|
|
265
|
+
|
|
266
|
+
- `file` — File object (used for metadata like name)
|
|
267
|
+
- `contentBodyId` — ContentBody ID from previous upload
|
|
268
|
+
- `recordId` — Record ID for FirstPublishLocationId
|
|
269
|
+
|
|
270
|
+
**Returns:** ContentVersion ID if successful
|
|
271
|
+
|
|
272
|
+
### getCurrentUserId()
|
|
273
|
+
|
|
274
|
+
Get the current user's Salesforce ID.
|
|
275
|
+
|
|
276
|
+
```typescript
|
|
277
|
+
async function getCurrentUserId(): Promise<string>;
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
**Returns:** Current user ID
|
|
281
|
+
|
|
282
|
+
## Common UI patterns
|
|
283
|
+
|
|
284
|
+
### File input with button
|
|
285
|
+
|
|
286
|
+
```tsx
|
|
287
|
+
<input type="file" multiple accept=".pdf,.doc,.docx,.jpg,.png" onChange={handleFileSelect} />
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Drag-and-drop zone
|
|
291
|
+
|
|
292
|
+
Build your own dropzone using native events:
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
function DropZone({ onDrop }: { onDrop: (files: File[]) => void }) {
|
|
296
|
+
const handleDrop = (e: React.DragEvent) => {
|
|
297
|
+
e.preventDefault();
|
|
298
|
+
const files = Array.from(e.dataTransfer.files);
|
|
299
|
+
onDrop(files);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
return (
|
|
303
|
+
<div
|
|
304
|
+
onDrop={handleDrop}
|
|
305
|
+
onDragOver={(e) => e.preventDefault()}
|
|
306
|
+
style={{ border: "2px dashed #ccc", padding: "2rem" }}
|
|
307
|
+
>
|
|
308
|
+
Drop files here
|
|
309
|
+
</div>
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Progress bar
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
{
|
|
318
|
+
progress.status === "uploading" && (
|
|
319
|
+
<div style={{ width: "100%", background: "#eee" }}>
|
|
320
|
+
<div
|
|
321
|
+
style={{
|
|
322
|
+
width: `${progress.progress}%`,
|
|
323
|
+
background: "#0176d3",
|
|
324
|
+
height: "8px",
|
|
325
|
+
}}
|
|
326
|
+
/>
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Decision tree for agents
|
|
333
|
+
|
|
334
|
+
**User asks for file upload functionality:**
|
|
335
|
+
|
|
336
|
+
1. **Ask about record context:**
|
|
337
|
+
- "Do you want to link uploaded files to a specific record, or upload them first and link later?"
|
|
338
|
+
|
|
339
|
+
2. **Based on response:**
|
|
340
|
+
- **Link to existing record** → Use Pattern B with `recordId`
|
|
341
|
+
- **Upload first, link later** → Use Pattern A (no recordId), then Pattern C for linking
|
|
342
|
+
- **Link to current user** → Use Pattern B with `getCurrentUserId()`
|
|
343
|
+
|
|
344
|
+
3. **Build the UI:**
|
|
345
|
+
- Create file input or dropzone (not provided by package)
|
|
346
|
+
- Add progress display for each file (status + progress bar)
|
|
347
|
+
- Handle errors in the UI
|
|
348
|
+
|
|
349
|
+
4. **Test the implementation:**
|
|
350
|
+
- Verify progress callbacks fire correctly
|
|
351
|
+
- Check that `contentBodyId` is returned
|
|
352
|
+
- If `recordId` was provided, verify `contentVersionId` is returned
|
|
353
|
+
|
|
354
|
+
## Reference implementation
|
|
355
|
+
|
|
356
|
+
The package includes a reference implementation in `src/features/fileupload/` with:
|
|
357
|
+
|
|
358
|
+
- `FileUpload.tsx` — Complete component with dropzone and dialog
|
|
359
|
+
- `FileUploadDialog.tsx` — Progress tracking dialog
|
|
360
|
+
- `FileUploadDropZone.tsx` — Drag-and-drop zone
|
|
361
|
+
- `useFileUpload.ts` — React hook for state management
|
|
362
|
+
|
|
363
|
+
**These are NOT exported** but can be viewed as examples. Read the source files to understand patterns for building your own UI.
|
|
364
|
+
|
|
365
|
+
## Troubleshooting
|
|
366
|
+
|
|
367
|
+
**Upload fails with CORS error:**
|
|
368
|
+
|
|
369
|
+
- Ensure the webapp is properly deployed to Salesforce or running on `localhost`
|
|
370
|
+
- Check that the org allows the origin in CORS settings
|
|
371
|
+
|
|
372
|
+
**No progress updates:**
|
|
373
|
+
|
|
374
|
+
- Verify `onProgress` callback is provided
|
|
375
|
+
- Check that the callback function updates React state correctly
|
|
376
|
+
|
|
377
|
+
**ContentVersion not created:**
|
|
378
|
+
|
|
379
|
+
- Verify `recordId` is provided to `upload()` function
|
|
380
|
+
- Check that the record ID is valid and exists in the org
|
|
381
|
+
- Ensure user has permissions to create ContentVersion records
|
|
382
|
+
|
|
383
|
+
**Files upload but don't appear in record:**
|
|
384
|
+
|
|
385
|
+
- Verify `recordId` is correct
|
|
386
|
+
- Check that ContentVersion was created (look for `contentVersionId` in results)
|
|
387
|
+
- Confirm user has access to view files on the record
|
|
388
|
+
|
|
389
|
+
## DO NOT do these things
|
|
390
|
+
|
|
391
|
+
- ❌ Build XHR/fetch upload logic from scratch — use the `upload()` API
|
|
392
|
+
- ❌ Try to import `<FileUpload />` component — it's not exported
|
|
393
|
+
- ❌ Try to import `useFileUpload` hook — it's not exported
|
|
394
|
+
- ❌ Use third-party file upload libraries when this feature exists
|
|
395
|
+
- ❌ Skip progress tracking — always provide user feedback
|
|
396
|
+
- ❌ Ignore errors — always handle and display error messages
|