@salesforce/afv-skills 1.5.1 → 1.5.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.
- package/README.md +16 -416
- package/package.json +5 -3
- package/skills/building-ui-bundle-app/SKILL.md +325 -0
- package/skills/building-ui-bundle-frontend/SKILL.md +122 -0
- package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/component.md +1 -1
- package/skills/creating-b2b-commerce-store/SKILL.md +169 -0
- package/skills/creating-b2b-commerce-store/references/store-vs-storefront.md +169 -0
- package/skills/deploying-ui-bundle/SKILL.md +77 -0
- package/skills/generating-apex/CREDITS.md +30 -0
- package/skills/generating-apex/SKILL.md +342 -189
- package/skills/generating-apex/assets/abstract.cls +12 -9
- package/skills/generating-apex/assets/batch.cls +7 -8
- package/skills/generating-apex/assets/domain.cls +5 -6
- package/skills/generating-apex/assets/dto.cls +11 -12
- package/skills/generating-apex/assets/exception.cls +1 -2
- package/skills/generating-apex/assets/interface.cls +2 -3
- package/skills/generating-apex/assets/invocable.cls +114 -0
- package/skills/generating-apex/assets/queueable.cls +6 -7
- package/skills/generating-apex/assets/rest-resource.cls +300 -0
- package/skills/generating-apex/assets/schedulable.cls +7 -8
- package/skills/generating-apex/assets/selector.cls +7 -8
- package/skills/generating-apex/assets/service.cls +4 -5
- package/skills/generating-apex/assets/trigger.cls +45 -0
- package/skills/generating-apex/assets/utility.cls +5 -6
- package/skills/generating-apex/references/AccountDeduplicationBatch.cls +7 -8
- package/skills/generating-apex/references/AccountSelector.cls +10 -11
- package/skills/generating-apex/references/AccountService.cls +9 -10
- package/skills/generating-apex-test/CREDITS.md +30 -0
- package/skills/generating-apex-test/SKILL.md +165 -74
- package/skills/generating-apex-test/assets/test-class-template.cls +25 -56
- package/skills/generating-apex-test/assets/test-data-factory-template.cls +0 -1
- package/skills/generating-apex-test/references/assertion-patterns.md +38 -95
- package/skills/generating-apex-test/references/async-testing.md +59 -142
- package/skills/generating-apex-test/references/mocking-patterns.md +77 -76
- package/skills/generating-apex-test/references/test-data-factory.md +29 -130
- package/skills/generating-experience-react-site/SKILL.md +9 -9
- package/skills/generating-experience-react-site/docs/configure-metadata-digital-experience.md +1 -1
- package/skills/generating-flexipage/SKILL.md +28 -12
- package/skills/generating-ui-bundle-features/SKILL.md +45 -0
- package/skills/generating-ui-bundle-metadata/SKILL.md +106 -0
- package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/SKILL.md +5 -5
- package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/constraints.md +2 -2
- package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/examples.md +1 -1
- package/skills/{implementing-webapp-file-upload → implementing-ui-bundle-file-upload}/SKILL.md +11 -11
- package/skills/searching-media/SKILL.md +1 -1
- package/skills/uplifting-components-to-slds2/SKILL.md +236 -0
- package/skills/uplifting-components-to-slds2/references/color-hooks-decision-guide.md +438 -0
- package/skills/uplifting-components-to-slds2/references/common-patterns.md +87 -0
- package/skills/uplifting-components-to-slds2/references/examples.md +443 -0
- package/skills/uplifting-components-to-slds2/references/migration-checklist.md +67 -0
- package/skills/uplifting-components-to-slds2/references/non-color-hooks-decision-guide.md +333 -0
- package/skills/uplifting-components-to-slds2/references/rule-lwc-token-to-slds-hook.md +135 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-deprecated-tokens-slds1.md +211 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-hardcoded-values.md +160 -0
- package/skills/uplifting-components-to-slds2/references/rule-no-slds-class-overrides.md +126 -0
- package/skills/{using-webapp-salesforce-data → using-ui-bundle-salesforce-data}/SKILL.md +52 -25
- package/skills/using-ui-bundle-salesforce-data/references/mutation-query-generation.md +140 -0
- package/skills/using-ui-bundle-salesforce-data/references/query-testing.md +78 -0
- package/skills/using-ui-bundle-salesforce-data/references/read-query-generation.md +307 -0
- package/skills/using-ui-bundle-salesforce-data/references/schema-introspection.md +53 -0
- package/skills/using-ui-bundle-salesforce-data/references/ui-bundle-integration.md +221 -0
- package/skills/{using-webapp-salesforce-data → using-ui-bundle-salesforce-data/scripts}/graphql-search.sh +75 -23
- package/skills/building-webapp-data-visualization/SKILL.md +0 -72
- package/skills/building-webapp-data-visualization/implementation/bar-line-chart.md +0 -316
- package/skills/building-webapp-data-visualization/implementation/dashboard-layout.md +0 -189
- package/skills/building-webapp-data-visualization/implementation/donut-chart.md +0 -181
- package/skills/building-webapp-data-visualization/implementation/stat-card.md +0 -150
- package/skills/building-webapp-react-components/SKILL.md +0 -96
- package/skills/configuring-webapp-csp-trusted-sites/SKILL.md +0 -90
- package/skills/configuring-webapp-metadata/SKILL.md +0 -158
- package/skills/creating-webapp/SKILL.md +0 -138
- package/skills/deploying-webapp-to-salesforce/SKILL.md +0 -226
- package/skills/installing-webapp-features/SKILL.md +0 -210
- /package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/header-footer.md +0 -0
- /package/skills/{building-webapp-react-components → building-ui-bundle-frontend}/implementation/page.md +0 -0
- /package/skills/{configuring-webapp-csp-trusted-sites/implementation/metadata-format.md → generating-ui-bundle-metadata/implementation/csp-metadata-format.md} +0 -0
- /package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/style-tokens.md +0 -0
- /package/skills/{managing-webapp-agentforce-conversation-client → implementing-ui-bundle-agentforce-conversation-client}/references/troubleshooting.md +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Rule: No Hardcoded Values
|
|
2
|
+
|
|
3
|
+
**Rule ID:** `slds/no-hardcoded-values-slds2`
|
|
4
|
+
**Severity:** Warning
|
|
5
|
+
**Scope:** All CSS properties with hardcoded values that have SLDS 2 hook equivalents — colors, spacing, sizing, typography, borders, radius, and shadows.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What the Linter Does
|
|
10
|
+
|
|
11
|
+
The linter detects hardcoded values and reports them as warnings. Here's real output for an icon component:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
3:10 warning Consider replacing the 32px static value with an SLDS 2 styling hook
|
|
15
|
+
that has a similar value: --slds-g-sizing-9. slds/no-hardcoded-values-slds2
|
|
16
|
+
|
|
17
|
+
5:21 warning Dynamic element with css-class "icon-container" using static value
|
|
18
|
+
"#066afe" for "background-color" css property. Consider replacing
|
|
19
|
+
the #066AFE static value with an SLDS 2 styling hook:
|
|
20
|
+
1. --slds-g-color-surface-inverse-1
|
|
21
|
+
2. --slds-g-color-surface-inverse-2
|
|
22
|
+
3. --slds-g-color-surface-container-inverse-1 slds/no-hardcoded-values-slds2
|
|
23
|
+
|
|
24
|
+
9:9 warning Dynamic element with css-class "account-icon" using static value
|
|
25
|
+
"#ffffff" for "fill" css property. Consider replacing:
|
|
26
|
+
1. --slds-g-color-on-accent-1
|
|
27
|
+
2. --slds-g-color-on-accent-2
|
|
28
|
+
3. --slds-g-color-error-base-95
|
|
29
|
+
4. --slds-g-color-warning-base-95 slds/no-hardcoded-values-slds2
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Non-color values** get single suggestions — auto-fixable with `--fix`:
|
|
33
|
+
|
|
34
|
+
```css
|
|
35
|
+
/* 32px → sizing-9 (single suggestion, auto-fixed) */
|
|
36
|
+
width: var(--slds-g-sizing-9, 32px);
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
**Color values** get multiple suggestions — requires manual selection. The linter suggests hooks based on color-value similarity, **not semantic context**. You must inspect the HTML to choose correctly.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## What to Fix vs What to Skip
|
|
44
|
+
|
|
45
|
+
| Property Type | Example Values | Action |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| Color properties (`color`, `fill`, `background`, `background-color`, `stroke`, `border-*-color`, `outline-color`) | `#fff`, `rgb(0,0,0)` | **Fix** — replace with color hook + fallback |
|
|
48
|
+
| Spacing properties (`margin`, `padding`, `gap`) | `16px`, `1rem`, `24px` | **Fix** — replace with spacing hook + fallback |
|
|
49
|
+
| Sizing properties (`width`, `height`, `min-*`, `max-*`) | `32px`, `2rem` | **Fix** — replace with sizing hook + fallback |
|
|
50
|
+
| Font properties (`font-size`, `font-weight`, `line-height`) | `14px`, `bold`, `1.5` | **Fix** — replace with typography hook + fallback |
|
|
51
|
+
| Border properties (`border-radius`, `border-width`) | `8px`, `1px` | **Fix** — replace with radius/border hook + fallback |
|
|
52
|
+
| Shadow properties (`box-shadow`) | `0 4px 8px rgba(…)` | **Fix** — replace with shadow hook + fallback |
|
|
53
|
+
| Layout/structural values | `100%`, `auto`, `0`, `inherit`, `none` | **Skip** — leave unchanged, removing breaks rendering |
|
|
54
|
+
|
|
55
|
+
When the linter says "Remove the static value" for a layout value like `width: 100%` or `height: auto`, **do not remove it**.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Replacement Pattern
|
|
60
|
+
|
|
61
|
+
Always include the original value as fallback:
|
|
62
|
+
|
|
63
|
+
```css
|
|
64
|
+
property: var(--slds-g-[hook], originalValue);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The fallback must be the **exact original value** from the source CSS (e.g., `#066AFE`, not a converted equivalent).
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Decision Tree
|
|
72
|
+
|
|
73
|
+
When examining a hardcoded value or deprecated token, follow this decision tree:
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
1. SLDS utility class available?
|
|
77
|
+
└─ Yes → Remove CSS, add utility class to HTML
|
|
78
|
+
└─ No ↓
|
|
79
|
+
|
|
80
|
+
2. At least one 1:1 styling hook mapping?
|
|
81
|
+
├─ Exactly one → Use it with fallback
|
|
82
|
+
├─ Multiple → Inspect HTML context to choose (see decision guides)
|
|
83
|
+
└─ None ↓
|
|
84
|
+
|
|
85
|
+
3. No exact match
|
|
86
|
+
└─ No close match → Leave hardcoded
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Step 1: Check for Utility Classes
|
|
90
|
+
|
|
91
|
+
If an SLDS utility class sets the exact property to the exact value, remove the CSS and replace with the class on the HTML element(s).
|
|
92
|
+
|
|
93
|
+
**Best fit vs perfect fit:** Use existing utilities that get you close enough, even if it means combining two or three classes. This keeps markup readable, styles consistent, and avoids unnecessary custom CSS. Don't write new CSS rules for edge cases unless absolutely necessary.
|
|
94
|
+
|
|
95
|
+
**When modifying CSS classes:**
|
|
96
|
+
- Before removing a CSS declaration, ensure you understand how it's used in HTML and in JS (computed classes)
|
|
97
|
+
- Update any tests after changing CSS classes — some tests use class query selectors that should be replaced with `data-tid` attributes
|
|
98
|
+
|
|
99
|
+
#### Example: Replacing with Utility Classes
|
|
100
|
+
|
|
101
|
+
Common CSS like `display: flex` with alignment can often be replaced entirely:
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
/* Before — component.css */
|
|
105
|
+
.container {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-direction: row;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
align-items: center;
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<!-- Before — component.html -->
|
|
115
|
+
<div class="container">
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
These styles map to SLDS grid utility classes:
|
|
119
|
+
|
|
120
|
+
```html
|
|
121
|
+
<!-- After — component.html (CSS removed entirely) -->
|
|
122
|
+
<div class="slds-grid slds-grid_align-center slds-grid_vertical-align-center">
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Note: `flex-direction: row` is the default for `display: flex` — it can be removed entirely.
|
|
126
|
+
|
|
127
|
+
### Steps 2 & 3: Choose the Right Hook
|
|
128
|
+
|
|
129
|
+
For choosing between multiple hooks or finding the closest match, see the decision guides:
|
|
130
|
+
|
|
131
|
+
| Category | Decision Guide |
|
|
132
|
+
|---|---|
|
|
133
|
+
| Color (background, foreground, border color) | [color-hooks-decision-guide.md](color-hooks-decision-guide.md) — surface vs container, semantic vs palette, applied examples from real PRs |
|
|
134
|
+
| Spacing, sizing, typography, borders, radius, shadows | [non-color-hooks-decision-guide.md](non-color-hooks-decision-guide.md) — numbered scales, closest-match rules, density-aware variants |
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Common Mistakes
|
|
139
|
+
|
|
140
|
+
1. **Inventing hook names** — Only use hooks documented in the SLDS design system.
|
|
141
|
+
2. **Missing fallback** — Always include the original value: `var(--slds-g-hook, originalValue)`
|
|
142
|
+
3. **Confusing spacing and sizing** — Spacing is for margins/padding/gaps. Sizing is for width/height/dimensions.
|
|
143
|
+
4. **Using named hooks** — `--slds-g-spacing-medium`, `--slds-g-font-weight-bold`, `--slds-g-radius-large` do NOT exist. Only numbered hooks exist.
|
|
144
|
+
5. **Replacing layout values** — Don't replace `100%`, `auto`, `flex: 1`, `none`, or `0` with hooks.
|
|
145
|
+
6. **Blindly trusting linter suggestions for colors** — The linter matches by color value, not semantic context. Always inspect HTML before choosing.
|
|
146
|
+
|
|
147
|
+
## What NOT to Replace
|
|
148
|
+
|
|
149
|
+
Leave these unchanged (no SLDS hooks apply):
|
|
150
|
+
|
|
151
|
+
```css
|
|
152
|
+
width: 100%; /* layout values */
|
|
153
|
+
height: auto; /* layout values */
|
|
154
|
+
flex: 1; /* layout values */
|
|
155
|
+
display: none; /* layout values */
|
|
156
|
+
transition: color 0.3s ease; /* animation values */
|
|
157
|
+
opacity: 0.5; /* opacity */
|
|
158
|
+
background: linear-gradient(…); /* gradients */
|
|
159
|
+
left: 50%; /* positioning offsets */
|
|
160
|
+
```
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Rule: No SLDS Class Overrides
|
|
2
|
+
|
|
3
|
+
**Rule ID:** `slds/no-slds-class-overrides`
|
|
4
|
+
**Severity:** Warning
|
|
5
|
+
**Scope:** Detects CSS selectors that directly target `.slds-*` classes.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What the Linter Does
|
|
10
|
+
|
|
11
|
+
The linter detects CSS classes that directly override SLDS classes and reports them as **warnings**. It does **not** auto-fix — all changes require manual work in both CSS and HTML.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
1:1 warning Overriding slds-button isn't supported. To differentiate SLDS and
|
|
15
|
+
custom classes, create a CSS class in your namespace.
|
|
16
|
+
Examples: myapp-input, myapp-button. slds/no-slds-class-overrides
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
**Manual steps required:**
|
|
20
|
+
1. Rename `.slds-*` selectors in CSS to `{componentName}-{sldsElementPart}`
|
|
21
|
+
2. Add the new component class to markup (`.html` for LWC, `.cmp` for Aura) **alongside** the original SLDS class
|
|
22
|
+
3. Never remove the original SLDS class from markup
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Naming Convention
|
|
27
|
+
|
|
28
|
+
**Format:** `{componentName}-{sldsElementPart}` (camelCase component name)
|
|
29
|
+
|
|
30
|
+
| SLDS Class | Component: `userProfile` | Result |
|
|
31
|
+
|---|---|---|
|
|
32
|
+
| `.slds-button` | `userProfile` | `userProfile-button` |
|
|
33
|
+
| `.slds-card` | `userProfile` | `userProfile-card` |
|
|
34
|
+
| `.slds-modal__content` | `userProfile` | `userProfile-modal__content` |
|
|
35
|
+
| `.slds-button_brand` | `userProfile` | `userProfile-button_brand` |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Common Patterns
|
|
40
|
+
|
|
41
|
+
### Pattern 1: Simple Selector
|
|
42
|
+
|
|
43
|
+
```css
|
|
44
|
+
/* Before CSS */
|
|
45
|
+
.slds-button { border-radius: 8px; }
|
|
46
|
+
|
|
47
|
+
/* After CSS */
|
|
48
|
+
.myComponent-button { border-radius: 8px; }
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<!-- After HTML (manual) -->
|
|
53
|
+
<button class="slds-button myComponent-button">Click</button>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Pattern 2: Descendant Selector
|
|
57
|
+
|
|
58
|
+
```css
|
|
59
|
+
/* Before CSS */
|
|
60
|
+
.slds-card .slds-button { margin-top: 1rem; }
|
|
61
|
+
|
|
62
|
+
/* After CSS */
|
|
63
|
+
.myComponent-card .myComponent-button { margin-top: 1rem; }
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<!-- After HTML (manual) — each SLDS class gets a component class -->
|
|
68
|
+
<div class="slds-card myComponent-card">
|
|
69
|
+
<button class="slds-button myComponent-button">Click</button>
|
|
70
|
+
</div>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Pattern 3: Multi-Class Selector
|
|
74
|
+
|
|
75
|
+
```css
|
|
76
|
+
/* Before CSS */
|
|
77
|
+
.slds-card.slds-p-around_medium { border: 1px solid blue; }
|
|
78
|
+
|
|
79
|
+
/* After CSS */
|
|
80
|
+
.myComponent-card.myComponent-p-around_medium { border: 1px solid blue; }
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
```html
|
|
84
|
+
<!-- After HTML (manual) -->
|
|
85
|
+
<div class="slds-card slds-p-around_medium myComponent-card myComponent-p-around_medium">
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Core Rules
|
|
91
|
+
|
|
92
|
+
1. **Never remove SLDS classes** from markup (`.html` or `.cmp`) — only ADD component classes alongside them
|
|
93
|
+
2. **One-to-one mapping** — each SLDS class in a CSS selector gets exactly one component class
|
|
94
|
+
3. **CamelCase component name** — `sampleComponent-button`, not `sample-component-button`
|
|
95
|
+
4. **Preserve SLDS element names** — `.slds-button` becomes `componentName-button` (strip `slds-` prefix, keep the rest)
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Interaction with Other Rules
|
|
100
|
+
|
|
101
|
+
If the overridden CSS properties include hardcoded colors, you must also apply `rule-no-hardcoded-values.md` to those properties:
|
|
102
|
+
|
|
103
|
+
```css
|
|
104
|
+
/* Before */
|
|
105
|
+
.slds-icon-action-check { background: #4bca81; }
|
|
106
|
+
|
|
107
|
+
/* After — both rules applied */
|
|
108
|
+
.myComponent-icon-action-check { background: var(--slds-g-color-success-base-70, #4bca81); }
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Validation Checklist
|
|
116
|
+
|
|
117
|
+
**CSS:**
|
|
118
|
+
- [ ] All `.slds-*` overrides reported by the linter are addressed
|
|
119
|
+
- [ ] Component name is camelCase
|
|
120
|
+
- [ ] SLDS element names preserved after prefix
|
|
121
|
+
|
|
122
|
+
**Markup (`.html` for LWC, `.cmp` for Aura):**
|
|
123
|
+
- [ ] Original SLDS classes preserved
|
|
124
|
+
- [ ] Component classes added alongside SLDS classes
|
|
125
|
+
- [ ] Every element in CSS selector chain updated in markup
|
|
126
|
+
- [ ] One component class per SLDS class
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
name: using-
|
|
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
|
|
2
|
+
name: using-ui-bundle-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 UI bundle 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
4
|
---
|
|
5
5
|
|
|
6
6
|
# Salesforce Data Access
|
|
@@ -17,7 +17,7 @@ Use this skill when the user wants to:
|
|
|
17
17
|
|
|
18
18
|
## Data SDK Requirement
|
|
19
19
|
|
|
20
|
-
> **All Salesforce data access MUST use the Data SDK** (`@salesforce/sdk-data`). The SDK handles authentication, CSRF, and base URL resolution.
|
|
20
|
+
> **All Salesforce data access MUST use the Data SDK** (`@salesforce/sdk-data`). The SDK handles authentication, CSRF, and base URL resolution.
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
23
|
import { createDataSDK, gql } from "@salesforce/sdk-data";
|
|
@@ -48,7 +48,7 @@ const res = await sdk.fetch?.("/services/apexrest/my-resource");
|
|
|
48
48
|
**Not supported:**
|
|
49
49
|
|
|
50
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
|
|
51
|
+
- **Aura-enabled Apex** (`@AuraEnabled`) — an LWC/Aura pattern with no invocation path from React UI bundles.
|
|
52
52
|
- **Chatter API** (`/chatter/users/me`) — use `uiapi { currentUser { ... } }` in a GraphQL query instead.
|
|
53
53
|
- **Any other Salesforce REST endpoint** not listed in the supported table above.
|
|
54
54
|
|
|
@@ -67,6 +67,24 @@ const res = await sdk.fetch?.("/services/apexrest/my-resource");
|
|
|
67
67
|
|
|
68
68
|
---
|
|
69
69
|
|
|
70
|
+
## GraphQL Non-Negotiable Rules
|
|
71
|
+
|
|
72
|
+
These rules exist because Salesforce GraphQL has platform-specific behaviors that differ from standard GraphQL. Violations cause silent runtime failures.
|
|
73
|
+
|
|
74
|
+
1. **Schema is the single source of truth** — Every entity name, field name, and type must be confirmed via the schema search script before use in a query. Never guess — Salesforce field names are case-sensitive, relationships may be polymorphic, and custom objects use suffixes (`__c`, `__e`). See [Schema Introspection](references/schema-introspection.md) for entity identification and iterative lookup procedures.
|
|
75
|
+
|
|
76
|
+
2. **`@optional` on all record fields** (read queries) — Salesforce field-level security (FLS) causes queries to fail entirely if the user lacks access to even one field. The `@optional` directive (v65+) tells the server to omit inaccessible fields instead of failing. Apply it to every scalar field, parent relationship, and child relationship. Consuming code must use optional chaining (`?.`) and nullish coalescing (`??`).
|
|
77
|
+
|
|
78
|
+
3. **Correct mutation syntax** — Mutations wrap under `uiapi(input: { allOrNone: true/false })`, not bare `uiapi { ... }`. Always set `allOrNone` explicitly. Output fields cannot include child relationships or navigated reference fields. See [Mutation Query Generation](references/mutation-query-generation.md).
|
|
79
|
+
|
|
80
|
+
4. **Explicit pagination** — Always include `first:` in every query. If omitted, the server silently defaults to 10 records. Include `pageInfo { hasNextPage endCursor }` for any query that may need pagination.
|
|
81
|
+
|
|
82
|
+
5. **SOQL-derived execution limits** — Max 10 subqueries per request, max 5 levels of child-to-parent traversal, max 1 level of parent-to-child (no grandchildren), max 2,000 records per subquery. If a query would exceed these, split into multiple requests.
|
|
83
|
+
|
|
84
|
+
6. **HTTP 200 does not mean success** — Salesforce returns HTTP 200 even when operations fail. Always parse the `errors` array in the response body.
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
70
88
|
## GraphQL Workflow
|
|
71
89
|
|
|
72
90
|
### Step 1: Acquire Schema
|
|
@@ -74,7 +92,7 @@ const res = await sdk.fetch?.("/services/apexrest/my-resource");
|
|
|
74
92
|
The `schema.graphql` file (265K+ lines) is the source of truth. **Never open or parse it directly.**
|
|
75
93
|
|
|
76
94
|
1. Check if `schema.graphql` exists at the SFDX project root
|
|
77
|
-
2. If missing, run from the **
|
|
95
|
+
2. If missing, run from the **UI bundle dir**: `npm run graphql:schema`
|
|
78
96
|
3. Custom objects appear only after metadata is deployed
|
|
79
97
|
|
|
80
98
|
### Step 2: Look Up Entity Schema
|
|
@@ -82,11 +100,11 @@ The `schema.graphql` file (265K+ lines) is the source of truth. **Never open or
|
|
|
82
100
|
Map user intent to PascalCase names ("accounts" → `Account`), then **run the search script from the project root**:
|
|
83
101
|
|
|
84
102
|
```bash
|
|
85
|
-
#
|
|
86
|
-
bash
|
|
103
|
+
# Look up all relevant schema info for one or more entities
|
|
104
|
+
bash scripts/graphql-search.sh Account
|
|
87
105
|
|
|
88
106
|
# Multiple entities at once
|
|
89
|
-
bash
|
|
107
|
+
bash scripts/graphql-search.sh Account Contact Opportunity
|
|
90
108
|
```
|
|
91
109
|
|
|
92
110
|
The script outputs five sections per entity:
|
|
@@ -96,11 +114,11 @@ The script outputs five sections per entity:
|
|
|
96
114
|
4. **Create input** — fields accepted by create mutations
|
|
97
115
|
5. **Update input** — fields accepted by update mutations
|
|
98
116
|
|
|
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.
|
|
117
|
+
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. For entity identification procedures (`_Record` suffix, `__c` conventions) and iterative introspection cycles, see [Schema Introspection](references/schema-introspection.md).
|
|
100
118
|
|
|
101
119
|
### Step 3: Generate Query
|
|
102
120
|
|
|
103
|
-
Use the templates below. Every field name **must** be verified from the script output in Step 2.
|
|
121
|
+
Use the templates below. Every field name **must** be verified from the script output in Step 2. For detailed generation rules, filtering, pagination, ordering, semi-joins, and field value wrappers, see [Read Query Generation](references/read-query-generation.md). For mutation chaining, input/output constraints, and transactional semantics, see [Mutation Query Generation](references/mutation-query-generation.md).
|
|
104
122
|
|
|
105
123
|
#### Read Query Template
|
|
106
124
|
|
|
@@ -138,7 +156,7 @@ const name = node.Name?.value ?? "";
|
|
|
138
156
|
|
|
139
157
|
```graphql
|
|
140
158
|
mutation CreateAccount($input: AccountCreateInput!) {
|
|
141
|
-
uiapi {
|
|
159
|
+
uiapi(input: { allOrNone: true }) {
|
|
142
160
|
AccountCreate(input: $input) {
|
|
143
161
|
Record { Id Name { value } }
|
|
144
162
|
}
|
|
@@ -215,21 +233,26 @@ const fields = response?.data?.uiapi?.objectInfos?.[0]?.fields ?? [];
|
|
|
215
233
|
|
|
216
234
|
### Step 4: Validate & Test
|
|
217
235
|
|
|
218
|
-
1. **Lint**: `npx eslint <file>` from
|
|
236
|
+
1. **Lint**: `npx eslint <file>` from UI bundle dir
|
|
219
237
|
2. **Test**: Ask user before testing. For mutations, request input values — never fabricate data.
|
|
220
238
|
|
|
221
239
|
**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
240
|
|
|
223
241
|
```bash
|
|
224
242
|
# From project root — re-check the entity that caused the error
|
|
225
|
-
bash
|
|
243
|
+
bash scripts/graphql-search.sh <EntityName>
|
|
226
244
|
```
|
|
227
245
|
|
|
228
|
-
Then fix the query using the exact names from the script output.
|
|
246
|
+
Then fix the query using the exact names from the script output. For detailed error categories, status handling, and retry strategy, see [Query Testing](references/query-testing.md).
|
|
229
247
|
|
|
230
248
|
---
|
|
231
249
|
|
|
232
|
-
##
|
|
250
|
+
## UI Bundle Integration (React)
|
|
251
|
+
|
|
252
|
+
Two integration patterns are available:
|
|
253
|
+
|
|
254
|
+
- **Pattern 1 — External `.graphql` file** (recommended for complex queries): Create a `.graphql` file, run `npm run graphql:codegen`, import with `?raw` suffix
|
|
255
|
+
- **Pattern 2 — Inline `gql` tag** (for simple queries): Use the `gql` template tag from `@salesforce/sdk-data`. **Must use `gql`** — plain template strings bypass ESLint schema validation.
|
|
233
256
|
|
|
234
257
|
```typescript
|
|
235
258
|
import { createDataSDK, gql } from "@salesforce/sdk-data";
|
|
@@ -242,8 +265,9 @@ const GET_ACCOUNTS = gql`
|
|
|
242
265
|
edges {
|
|
243
266
|
node {
|
|
244
267
|
Id
|
|
245
|
-
Name @optional {
|
|
246
|
-
|
|
268
|
+
Name @optional {
|
|
269
|
+
value
|
|
270
|
+
}
|
|
247
271
|
}
|
|
248
272
|
}
|
|
249
273
|
}
|
|
@@ -254,14 +278,14 @@ const GET_ACCOUNTS = gql`
|
|
|
254
278
|
|
|
255
279
|
const sdk = await createDataSDK();
|
|
256
280
|
const response = await sdk.graphql?.(GET_ACCOUNTS);
|
|
257
|
-
|
|
258
281
|
if (response?.errors?.length) {
|
|
259
282
|
throw new Error(response.errors.map(e => e.message).join("; "));
|
|
260
283
|
}
|
|
261
|
-
|
|
262
284
|
const accounts = response?.data?.uiapi?.query?.Account?.edges?.map(e => e.node) ?? [];
|
|
263
285
|
```
|
|
264
286
|
|
|
287
|
+
For detailed patterns (external .graphql files, codegen, error handling strategies, quality checklists), see [UI Bundle Integration](references/ui-bundle-integration.md).
|
|
288
|
+
|
|
265
289
|
---
|
|
266
290
|
|
|
267
291
|
## REST API Patterns
|
|
@@ -311,16 +335,16 @@ const response = await sdk.graphql?.(GET_CURRENT_USER);
|
|
|
311
335
|
<project-root>/ ← SFDX project root
|
|
312
336
|
├── schema.graphql ← grep target (lives here)
|
|
313
337
|
├── sfdx-project.json
|
|
314
|
-
└── force-app/main/default/
|
|
338
|
+
└── force-app/main/default/uiBundles/<app-name>/ ← UI bundle dir
|
|
315
339
|
├── package.json ← npm scripts
|
|
316
340
|
└── src/
|
|
317
341
|
```
|
|
318
342
|
|
|
319
343
|
| Command | Run From | Why |
|
|
320
344
|
|---------|----------|-----|
|
|
321
|
-
| `npm run graphql:schema` |
|
|
322
|
-
| `npx eslint <file>` |
|
|
323
|
-
| `bash
|
|
345
|
+
| `npm run graphql:schema` | UI bundle dir | Script in UI bundle's package.json |
|
|
346
|
+
| `npx eslint <file>` | UI bundle dir | Reads eslint.config.js |
|
|
347
|
+
| `bash scripts/graphql-search.sh <Entity>` | project root | Schema lookup |
|
|
324
348
|
| `sf api request rest` | project root | Needs sfdx-project.json |
|
|
325
349
|
|
|
326
350
|
---
|
|
@@ -332,7 +356,7 @@ const response = await sdk.graphql?.(GET_CURRENT_USER);
|
|
|
332
356
|
Run the search script to get all relevant schema info in one step:
|
|
333
357
|
|
|
334
358
|
```bash
|
|
335
|
-
bash
|
|
359
|
+
bash scripts/graphql-search.sh <EntityName>
|
|
336
360
|
```
|
|
337
361
|
|
|
338
362
|
| Script Output Section | Used For |
|
|
@@ -358,6 +382,9 @@ bash .a4drules/skills/using-salesforce-data/graphql-search.sh <EntityName>
|
|
|
358
382
|
### Checklist
|
|
359
383
|
|
|
360
384
|
- [ ] All field names verified via search script (Step 2)
|
|
361
|
-
- [ ] `@optional` applied to record fields (reads)
|
|
385
|
+
- [ ] `@optional` applied to all record fields (reads)
|
|
386
|
+
- [ ] Mutations use `uiapi(input: { allOrNone: ... })` wrapper
|
|
387
|
+
- [ ] `first:` specified in every query
|
|
362
388
|
- [ ] Optional chaining in consuming code
|
|
389
|
+
- [ ] `errors` array checked in response handling
|
|
363
390
|
- [ ] Lint passes: `npx eslint <file>`
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Mutation Query Generation
|
|
2
|
+
|
|
3
|
+
## Mutation Types
|
|
4
|
+
|
|
5
|
+
The GraphQL engine supports three mutation operations:
|
|
6
|
+
|
|
7
|
+
- **Create** — Insert a new record
|
|
8
|
+
- **Update** — Modify an existing record (Id-based)
|
|
9
|
+
- **Delete** — Remove an existing record (Id-based)
|
|
10
|
+
|
|
11
|
+
Mutations are GA in API v66+. They live under `mutation { uiapi { ... } }` and only support UI API-available objects.
|
|
12
|
+
|
|
13
|
+
## Generation Rules
|
|
14
|
+
|
|
15
|
+
1. **Input fields validation** — Validate that input fields satisfy the constraints for the operation type
|
|
16
|
+
2. **Output fields validation** — Validate that output fields satisfy the constraints for the operation type
|
|
17
|
+
3. **Type consistency** — Variables used as query arguments and their related fields must share the same GraphQL type. Verify types via the schema search script — do NOT assume types
|
|
18
|
+
4. **Input arguments** — `input` is the default argument name unless otherwise specified
|
|
19
|
+
5. **Output field** — For `Create` and `Update`, the output field is always named `Record` (type: EntityName)
|
|
20
|
+
6. **Field name validation** — Every field name in the generated mutation **MUST** match a field confirmed via the schema search script. Do NOT guess or assume field names exist
|
|
21
|
+
7. **Raw input values** — Numeric values must be raw numbers without commas, currency symbols, or locale formatting (e.g., `80000` not `"80,000"` or `"$80,000"`). Compound fields (like addresses) require constituent fields (e.g., `BillingCity`, `BillingStreet`) — do not attempt to set the compound wrapper itself.
|
|
22
|
+
|
|
23
|
+
## Transactional Semantics: `allOrNone`
|
|
24
|
+
|
|
25
|
+
The `uiapi` mutation input accepts an `allOrNone` argument that controls rollback behavior:
|
|
26
|
+
|
|
27
|
+
- **`allOrNone: true` (default)** — If any operation fails, all operations in the request are rolled back. Use when operations must succeed or fail together.
|
|
28
|
+
- **`allOrNone: false`** — Independent operations can succeed individually. However, dependent operations (those using `@{alias}` references) still roll back together with their dependencies.
|
|
29
|
+
|
|
30
|
+
Always set `allOrNone` explicitly to make transactional intent clear.
|
|
31
|
+
|
|
32
|
+
## Mutation Schema Patterns
|
|
33
|
+
|
|
34
|
+
Replace `EntityName` with the actual entity name (e.g., Account, Case). `Delete` operations use generic `Record` types.
|
|
35
|
+
|
|
36
|
+
```graphql
|
|
37
|
+
input EntityNameCreateRepresentation {
|
|
38
|
+
# Subset of EntityName fields
|
|
39
|
+
}
|
|
40
|
+
input EntityNameCreateInput { EntityName: EntityNameCreateRepresentation! }
|
|
41
|
+
type EntityNameCreatePayload { Record: EntityName! }
|
|
42
|
+
|
|
43
|
+
input EntityNameUpdateRepresentation {
|
|
44
|
+
# Subset of EntityName fields
|
|
45
|
+
}
|
|
46
|
+
input EntityNameUpdateInput { Id: IdOrRef! EntityName: EntityNameUpdateRepresentation! }
|
|
47
|
+
type EntityNameUpdatePayload { Record: EntityName! }
|
|
48
|
+
|
|
49
|
+
input RecordDeleteInput { Id: IdOrRef! }
|
|
50
|
+
type RecordDeletePayload { Id: ID }
|
|
51
|
+
|
|
52
|
+
type UIAPIMutations {
|
|
53
|
+
EntityNameCreate(input: EntityNameCreateInput!): EntityNameCreatePayload
|
|
54
|
+
EntityNameDelete(input: RecordDeleteInput!): RecordDeletePayload
|
|
55
|
+
EntityNameUpdate(input: EntityNameUpdateInput!): EntityNameUpdatePayload
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Input Field Constraints
|
|
60
|
+
|
|
61
|
+
### Create
|
|
62
|
+
|
|
63
|
+
- **Must** include all required fields (unless `defaultedOnCreate` is `true` and not explicitly requested)
|
|
64
|
+
- **Must** only include `createable` fields
|
|
65
|
+
- Child relationships cannot be set — exclude them
|
|
66
|
+
- Reference fields (`REFERENCE` type) can only be assigned IDs through their `ApiName` name
|
|
67
|
+
- **No nested child creates** — Creating a record with child relationships in a single create operation is not supported. To create a parent and child together, use separate operations with `IdOrRef` chaining (see [Mutation Chaining](#mutation-chaining)).
|
|
68
|
+
|
|
69
|
+
### Update
|
|
70
|
+
|
|
71
|
+
- **Must** include the `Id` of the entity to update
|
|
72
|
+
- **Must** only include `updateable` fields
|
|
73
|
+
- Child relationships cannot be set — exclude them
|
|
74
|
+
- Reference fields (`REFERENCE` type) can only be assigned IDs through their `ApiName` name
|
|
75
|
+
|
|
76
|
+
### Delete
|
|
77
|
+
|
|
78
|
+
- **Must** include the `Id` of the entity to delete
|
|
79
|
+
|
|
80
|
+
## Output Field Constraints
|
|
81
|
+
|
|
82
|
+
### Create and Update
|
|
83
|
+
|
|
84
|
+
- **Must** exclude all child relationships (child relationships cannot be queried in mutations)
|
|
85
|
+
- **Must** exclude all `REFERENCE` fields unless accessed through their `ApiName` member (no navigation to referenced entity, no sub fields)
|
|
86
|
+
- Inaccessible fields are reported in the `errors` attribute of the returned payload
|
|
87
|
+
|
|
88
|
+
### Delete
|
|
89
|
+
|
|
90
|
+
- **Must** only include the `Id` field
|
|
91
|
+
|
|
92
|
+
## Mutation Chaining
|
|
93
|
+
|
|
94
|
+
Chain related mutations in a single request using references to `Id` values from previous mutations. This is the required approach for creating parent-child records together, since nested child creates are not supported.
|
|
95
|
+
|
|
96
|
+
1. **Ordering** — Mutation `B` can reference mutation `A` only if `A` comes first in the query
|
|
97
|
+
2. **Notation** — Use `SomeId: "@{A}"` in mutation `B` to set a field to the `Id` produced by mutation `A`
|
|
98
|
+
3. **IDs only** — `@{A}` is always interpreted as the `Id` from mutation `A`
|
|
99
|
+
4. **Restrictions** — `A` must be a `Create` or `Delete` mutation (chaining from `Update` will fail)
|
|
100
|
+
|
|
101
|
+
### Chaining Example
|
|
102
|
+
|
|
103
|
+
```graphql
|
|
104
|
+
mutation CreateAccountAndContact {
|
|
105
|
+
uiapi(input: { allOrNone: true }) {
|
|
106
|
+
AccountCreate(input: { Account: { Name: "Acme" } }) {
|
|
107
|
+
Record { Id }
|
|
108
|
+
}
|
|
109
|
+
ContactCreate(input: { Contact: { LastName: "Smith", AccountId: "@{AccountCreate}" } }) {
|
|
110
|
+
Record { Id }
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Mutation Query Template
|
|
117
|
+
|
|
118
|
+
```graphql
|
|
119
|
+
mutation mutateEntityName(
|
|
120
|
+
# arguments
|
|
121
|
+
) {
|
|
122
|
+
uiapi(input: { allOrNone: true }) {
|
|
123
|
+
EntityNameOperation(input: {
|
|
124
|
+
# For Create and Update only:
|
|
125
|
+
EntityName: {
|
|
126
|
+
# Input fields — use raw values, no formatting
|
|
127
|
+
}
|
|
128
|
+
# For Update and Delete only:
|
|
129
|
+
Id: ... # id here
|
|
130
|
+
}) {
|
|
131
|
+
# For Create and Update only:
|
|
132
|
+
Record {
|
|
133
|
+
# Output fields
|
|
134
|
+
}
|
|
135
|
+
# For Delete only:
|
|
136
|
+
Id
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|