@salesforce/afv-skills 1.7.4 β 1.8.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/README.md +3 -3
- package/package.json +1 -1
- package/skills/building-ui-bundle-frontend/SKILL.md +2 -0
- package/skills/deploying-ui-bundle/SKILL.md +2 -0
- package/skills/developing-agentforce/SKILL.md +1 -1
- package/skills/developing-datacloud-code-extension/SKILL.md +321 -0
- package/skills/developing-datacloud-code-extension/references/README.md +193 -0
- package/skills/developing-datacloud-code-extension/references/quick-reference.md +269 -0
- package/skills/generating-apex/SKILL.md +4 -2
- package/skills/generating-apex-test/SKILL.md +3 -1
- package/skills/generating-custom-application/SKILL.md +2 -0
- package/skills/generating-custom-field/SKILL.md +3 -1
- package/skills/generating-custom-lightning-type/SKILL.md +2 -0
- package/skills/generating-custom-object/SKILL.md +3 -1
- package/skills/generating-custom-tab/SKILL.md +3 -1
- package/skills/generating-flexipage/SKILL.md +2 -0
- package/skills/generating-flow/SKILL.md +2 -0
- package/skills/generating-lightning-app/SKILL.md +1 -1
- package/skills/generating-list-view/SKILL.md +2 -0
- package/skills/generating-permission-set/SKILL.md +1 -1
- package/skills/generating-ui-bundle-features/SKILL.md +2 -0
- package/skills/generating-ui-bundle-metadata/SKILL.md +2 -0
- package/skills/generating-ui-bundle-site/SKILL.md +2 -0
- package/skills/generating-validation-rule/SKILL.md +2 -0
- package/skills/getting-datacloud-schema/SKILL.md +380 -0
- package/skills/getting-datacloud-schema/references/README.md +191 -0
- package/skills/getting-datacloud-schema/scripts/get_dlo_schema.py +244 -0
- package/skills/getting-datacloud-schema/scripts/get_dmo_schema.py +233 -0
- package/skills/implementing-ui-bundle-agentforce-conversation-client/SKILL.md +1 -1
- package/skills/implementing-ui-bundle-file-upload/SKILL.md +2 -0
- package/skills/observing-agentforce/SKILL.md +1 -1
- package/skills/switching-org/SKILL.md +1 -1
- package/skills/testing-agentforce/SKILL.md +1 -1
- package/skills/uplifting-components-to-slds2/SKILL.md +3 -1
- package/skills/using-ui-bundle-salesforce-data/SKILL.md +2 -0
- package/skills/trigger-refactor-pipeline/SKILL.md +0 -191
- package/skills/trigger-refactor-pipeline/assets/test_template.apex +0 -321
- package/skills/trigger-refactor-pipeline/references/handler_patterns.md +0 -442
- package/skills/trigger-refactor-pipeline/scripts/analyze_trigger.py +0 -258
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Salesforce Skills Library
|
|
2
2
|
|
|
3
3
|
This repository provides a curated collection of Salesforce agent skills for building applications. It includes skills for Agentforce agents, Lightning apps, Flow, Apex, SOQL, Lightning Web Components (LWC), UI bundles, objects and fields, permission sets, and related areas.
|
|
4
4
|
|
|
@@ -7,7 +7,7 @@ The skills are contributed by Salesforce and the broader community. Itβs optim
|
|
|
7
7
|
## ποΈ Structure
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
|
|
10
|
+
sf-skills/
|
|
11
11
|
βββ skills/ # Directory-based executable workflows
|
|
12
12
|
β βββ generating-apex/
|
|
13
13
|
β βββ generating-custom-object/
|
|
@@ -26,7 +26,7 @@ afv-library/
|
|
|
26
26
|
| **Tool** | **Usage** |
|
|
27
27
|
|----------|-------------|
|
|
28
28
|
| **Agentforce Vibes** | Skills are auto-installed and auto-updated |
|
|
29
|
-
| **OpenCode, Claude Code, Codex, Cursor, [more](https://agentskills.io/)** | `npx skills add forcedotcom/
|
|
29
|
+
| **OpenCode, Claude Code, Codex, Cursor, [more](https://agentskills.io/)** | `npx skills add forcedotcom/sf-skills` |
|
|
30
30
|
|
|
31
31
|
## π¦ Samples
|
|
32
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: building-ui-bundle-frontend
|
|
3
3
|
description: "MUST activate before editing ANY file under uiBundles/*/src/ for visual or UI changes to an EXISTING app β pages, components, sections, layout, styling, colors, fonts, navigation, animations, or any look-and-feel change. Use this skill when modifying pages, components, layout, styling, or navigation in an existing UI bundle app. Activate when the project contains appLayout.tsx, routes.tsx, src/pages/, src/components/, or global.css. This skill contains critical project-specific conventions (appLayout.tsx shell, shadcn/ui components, Tailwind CSS, Salesforce base-path routing, module restrictions) that override general knowledge. Without this skill, generated code will use wrong imports, break routing, or ignore project structure. Do NOT use when creating a new app from scratch (use building-ui-bundle-app instead)."
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# UI Bundle UI
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: deploying-ui-bundle
|
|
3
3
|
description: "MUST activate when the project contains a uiBundles/*/src/ directory or sfdx-project.json and the task involves deploying, pushing to an org, or post-deploy setup. Use this skill when deploying a UI bundle app to a Salesforce org. Covers the full deployment sequence: org authentication, pre-deploy build, metadata deployment, permission set assignment, data import, GraphQL schema fetch, and codegen. Activate when files like *.uibundle-meta.xml or sfdx-project.json exist and the user mentions deploying, pushing, org setup, or post-deploy tasks."
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0"
|
|
4
6
|
---
|
|
5
7
|
|
|
6
8
|
# Deploying a UI Bundle
|
|
@@ -4,7 +4,7 @@ description: "Build, modify, debug, and deploy agents with Agentforce Agent Scri
|
|
|
4
4
|
license: Apache-2.0
|
|
5
5
|
compatibility: "Requires Agentforce license, API v66.0+, Einstein Agent User"
|
|
6
6
|
metadata:
|
|
7
|
-
version: "0
|
|
7
|
+
version: "1.0"
|
|
8
8
|
last_updated: "2026-04-08"
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: developing-datacloud-code-extension
|
|
3
|
+
description: "Develop and deploy Data Cloud Code Extensions using SF CLI plugin. Use this skill when creating custom Python transformations for Data Cloud, deploying code extensions, or testing data transformations. Supports init, run, scan, and deploy operations."
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# developing-datacloud-code-extension Skill
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
This skill provides a complete workflow for developing, testing, and deploying custom Python code extensions to Salesforce Data Cloud. Code extensions allow you to write Python transformations that read from and write to Data Lake Objects (DLOs) and Data Model Objects (DMOs).
|
|
13
|
+
|
|
14
|
+
## When to Use
|
|
15
|
+
|
|
16
|
+
- User wants to create a new code extension project
|
|
17
|
+
- User needs to test a code extension locally
|
|
18
|
+
- User wants to scan code for required permissions
|
|
19
|
+
- User needs to deploy a code extension to Data Cloud
|
|
20
|
+
- User is working with Data Cloud transformations
|
|
21
|
+
- User wants to read/write DLO or DMO data programmatically
|
|
22
|
+
|
|
23
|
+
## Prerequisites Check
|
|
24
|
+
|
|
25
|
+
Before executing any code extension commands, verify prerequisites:
|
|
26
|
+
|
|
27
|
+
1. **SF CLI with plugin installed**
|
|
28
|
+
```bash
|
|
29
|
+
sf plugins --core | grep data-code-extension
|
|
30
|
+
```
|
|
31
|
+
If not installed:
|
|
32
|
+
```bash
|
|
33
|
+
sf plugins install @salesforce/plugin-data-codeextension
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
2. **Python 3.11**
|
|
37
|
+
```bash
|
|
38
|
+
python --version # Should show 3.11.x
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
3. **Data Cloud Custom Code SDK**
|
|
42
|
+
```bash
|
|
43
|
+
pip list | grep salesforce-data-customcode
|
|
44
|
+
```
|
|
45
|
+
If not installed:
|
|
46
|
+
```bash
|
|
47
|
+
pip install salesforce-data-customcode
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
4. **Docker running** (for deploy only)
|
|
51
|
+
```bash
|
|
52
|
+
docker ps
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
5. **Authenticated org**
|
|
56
|
+
```bash
|
|
57
|
+
sf org display --target-org <org_alias> --json
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Skill Workflow
|
|
61
|
+
|
|
62
|
+
### Phase 1: Initialize Project
|
|
63
|
+
|
|
64
|
+
Create a new code extension project with scaffolding.
|
|
65
|
+
|
|
66
|
+
**Commands:**
|
|
67
|
+
|
|
68
|
+
For **script-based** code extensions (batch transformations):
|
|
69
|
+
```bash
|
|
70
|
+
sf data-code-extension script init --package-dir <directory>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For **function-based** code extensions (real-time):
|
|
74
|
+
```bash
|
|
75
|
+
sf data-code-extension function init --package-dir <directory>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Required Option:**
|
|
79
|
+
- `--package-dir, -p` - Directory path where the package will be created
|
|
80
|
+
|
|
81
|
+
**What it creates:**
|
|
82
|
+
```
|
|
83
|
+
my-transform/ # Project root
|
|
84
|
+
βββ payload/ # CRITICAL: This is what --package-dir must point to for deploy
|
|
85
|
+
β βββ entrypoint.py # Main transformation code
|
|
86
|
+
β βββ config.json # Code extension configuration
|
|
87
|
+
βββ requirements.txt # Python dependencies
|
|
88
|
+
βββ README.md
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Directory Context During Workflow
|
|
92
|
+
|
|
93
|
+
**IMPORTANT:** Understanding the directory structure is critical for successful deployment.
|
|
94
|
+
|
|
95
|
+
**Commands and their directory requirements:**
|
|
96
|
+
|
|
97
|
+
| Command | Run From | Path/File Argument |
|
|
98
|
+
|---------|----------|-------------------|
|
|
99
|
+
| `init` | Parent directory | `<project-name>` or `.` |
|
|
100
|
+
| `scan` | Project root | `./payload/entrypoint.py` |
|
|
101
|
+
| `run` | Project root | `./payload/entrypoint.py` |
|
|
102
|
+
| `deploy` | Project root | `--package-dir ./payload` (**REQUIRED**) |
|
|
103
|
+
|
|
104
|
+
**CRITICAL: The `--package-dir` argument in deploy command MUST point to the `payload` directory, not the project root.**
|
|
105
|
+
|
|
106
|
+
### Phase 2: Develop Transformation
|
|
107
|
+
|
|
108
|
+
Edit `payload/entrypoint.py` with transformation logic.
|
|
109
|
+
|
|
110
|
+
**Script Example (Batch):**
|
|
111
|
+
```python
|
|
112
|
+
from datacustomcode import Client
|
|
113
|
+
|
|
114
|
+
client = Client()
|
|
115
|
+
|
|
116
|
+
# Read from DLO
|
|
117
|
+
df = client.read_dlo('Employee__dll')
|
|
118
|
+
|
|
119
|
+
# Transform data (uppercase position field)
|
|
120
|
+
df['position_upper'] = df['position'].str.upper()
|
|
121
|
+
|
|
122
|
+
# Write to output DLO
|
|
123
|
+
client.write_to_dlo('Employee_Upper__dll', df, 'overwrite')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
**Function Example (Real-time):**
|
|
127
|
+
```python
|
|
128
|
+
from datacustomcode import FunctionClient
|
|
129
|
+
|
|
130
|
+
def transform(event, context):
|
|
131
|
+
client = FunctionClient(context)
|
|
132
|
+
input_data = event['data']
|
|
133
|
+
output = {
|
|
134
|
+
'name': input_data['name'].upper(),
|
|
135
|
+
'status': 'processed'
|
|
136
|
+
}
|
|
137
|
+
return output
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Common Operations:**
|
|
141
|
+
- `client.read_dlo('DLO_Name__dll')` - Read from DLO
|
|
142
|
+
- `client.read_dmo('DMO_Name')` - Read from DMO
|
|
143
|
+
- `client.write_to_dlo('DLO_Name__dll', df, 'overwrite')` - Write to DLO
|
|
144
|
+
- `client.write_to_dmo('DMO_Name', df, 'upsert')` - Write to DMO
|
|
145
|
+
|
|
146
|
+
### Phase 3: Scan for Permissions
|
|
147
|
+
|
|
148
|
+
Scan the entrypoint file to detect required permissions and generate config.json.
|
|
149
|
+
|
|
150
|
+
**Command:**
|
|
151
|
+
```bash
|
|
152
|
+
sf data-code-extension script scan --entrypoint ./payload/entrypoint.py
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**What it detects:**
|
|
156
|
+
- Read permissions for DLOs/DMOs
|
|
157
|
+
- Write permissions for DLOs/DMOs
|
|
158
|
+
- Python package dependencies
|
|
159
|
+
- Updates `config.json` and `requirements.txt`
|
|
160
|
+
|
|
161
|
+
### Phase 4: Validate DLO Schema (Pre-Test Check)
|
|
162
|
+
|
|
163
|
+
**CRITICAL: Before running tests locally, validate that all DLOs used in your code exist and have the expected fields.**
|
|
164
|
+
|
|
165
|
+
#### Step 4a: Extract DLOs from config.json
|
|
166
|
+
|
|
167
|
+
After scanning, review the generated `config.json` to identify all DLOs:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
cat payload/config.json
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
#### Step 4b: Validate Each DLO Schema
|
|
174
|
+
|
|
175
|
+
**Use the `getting-datacloud-schema` skill to verify DLOs exist and check field names.**
|
|
176
|
+
|
|
177
|
+
For each DLO referenced in your code:
|
|
178
|
+
|
|
179
|
+
1. **Verify DLO exists:**
|
|
180
|
+
```bash
|
|
181
|
+
python3 scripts/get_dlo_schema.py <org_alias> <dlo_name>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
2. **Verify field names match** β compare fields used in your `entrypoint.py` against the DLO schema.
|
|
185
|
+
|
|
186
|
+
3. **Check all DLOs:**
|
|
187
|
+
- Validate all DLOs in `read` permissions
|
|
188
|
+
- Validate all DLOs in `write` permissions
|
|
189
|
+
- Check field names match exactly (case-sensitive)
|
|
190
|
+
- Verify data types are compatible with operations
|
|
191
|
+
|
|
192
|
+
#### Step 4c: Validation Checklist
|
|
193
|
+
|
|
194
|
+
Before proceeding to run, ensure:
|
|
195
|
+
|
|
196
|
+
- [ ] All DLOs in config.json exist in target org
|
|
197
|
+
- [ ] All field names used in code exist in DLO schemas
|
|
198
|
+
- [ ] Field data types match your transformation logic
|
|
199
|
+
- [ ] Primary key fields are correctly identified
|
|
200
|
+
- [ ] Write target DLOs are created and accessible
|
|
201
|
+
|
|
202
|
+
### Phase 5: Test Locally
|
|
203
|
+
|
|
204
|
+
After validating DLO schemas, run the code extension locally against your Data Cloud org.
|
|
205
|
+
|
|
206
|
+
**Command:**
|
|
207
|
+
```bash
|
|
208
|
+
sf data-code-extension script run --entrypoint <entrypoint_file> --target-org <org_alias> [options]
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Options:**
|
|
212
|
+
- `--target-org, -o` - SF CLI org alias (required)
|
|
213
|
+
- `--config-file, -c` - Custom config file path
|
|
214
|
+
|
|
215
|
+
**If you get errors:**
|
|
216
|
+
- Re-validate DLO schemas
|
|
217
|
+
- Check field names are exact matches
|
|
218
|
+
- Verify data types are compatible
|
|
219
|
+
- Review error messages for field/DLO issues
|
|
220
|
+
|
|
221
|
+
### Phase 6: Deploy to Data Cloud
|
|
222
|
+
|
|
223
|
+
Deploy the code extension to Data Cloud for scheduled or on-demand execution.
|
|
224
|
+
|
|
225
|
+
**CRITICAL: You MUST specify `--package-dir ./payload` to point to the payload directory created by init.**
|
|
226
|
+
|
|
227
|
+
**Command:**
|
|
228
|
+
```bash
|
|
229
|
+
sf data-code-extension script deploy --target-org <org_alias> --name <name> --package-dir ./payload --package-version <version> --description <description> [options]
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Required Options:**
|
|
233
|
+
- `--target-org, -o` - SF CLI org alias
|
|
234
|
+
- `--name, -n` - Name for code extension deployment
|
|
235
|
+
- `--package-dir` - Path to payload directory (**REQUIRED** - must be `./payload` when running from project root)
|
|
236
|
+
- `--package-version` - Version string (default: 0.0.1)
|
|
237
|
+
- `--description` - Description of code extension
|
|
238
|
+
|
|
239
|
+
**Optional Options:**
|
|
240
|
+
- `--cpu-size` - CPU size: CPU_L, CPU_XL, CPU_2XL (default), CPU_4XL
|
|
241
|
+
- `--function-invoke-opt` - Function invoke options (for function type)
|
|
242
|
+
- `--network` - Docker network (default: default)
|
|
243
|
+
|
|
244
|
+
**After deployment:**
|
|
245
|
+
- Navigate to Data Cloud in Salesforce UI
|
|
246
|
+
- Go to Data Transforms section
|
|
247
|
+
- Find your deployment by name
|
|
248
|
+
- Click "Run Now" to execute
|
|
249
|
+
- Schedule for recurring execution
|
|
250
|
+
|
|
251
|
+
## Error Handling
|
|
252
|
+
|
|
253
|
+
### Common Issues and Solutions
|
|
254
|
+
|
|
255
|
+
| Error | Solution |
|
|
256
|
+
|-------|----------|
|
|
257
|
+
| `command data-code-extension not found` | `sf plugins install @salesforce/plugin-data-codeextension` |
|
|
258
|
+
| `datacustomcode CLI not found` | `pip install salesforce-data-customcode` |
|
|
259
|
+
| `Python version mismatch` | Use pyenv: `pyenv install 3.11.0 && pyenv local 3.11.0` |
|
|
260
|
+
| `Cannot connect to Docker daemon` | Start Docker Desktop |
|
|
261
|
+
| `No org found for alias` | `sf org login web --alias <org_alias>` |
|
|
262
|
+
| `config.json not found` | `sf data-code-extension script scan --entrypoint ./payload/entrypoint.py` |
|
|
263
|
+
| `DLO not found` | Verify DLO exists (use getting-datacloud-schema skill), check spelling and `__dll` suffix |
|
|
264
|
+
| `Permission denied writing` | Re-run scan, verify target DLO exists and is writable |
|
|
265
|
+
| `Deploy fails - wrong directory` | Ensure `--package-dir` points to `payload/` directory, not project root |
|
|
266
|
+
|
|
267
|
+
## Best Practices
|
|
268
|
+
|
|
269
|
+
### Development
|
|
270
|
+
1. Always scan before testing β run scan after code changes
|
|
271
|
+
2. Test locally first β use `run` command before deploying
|
|
272
|
+
3. Use version control β git commit after each successful test
|
|
273
|
+
4. Version your deployments β use semantic versioning (1.0.0, 1.1.0, etc.)
|
|
274
|
+
5. Deploy from project root with `--package-dir ./payload`
|
|
275
|
+
|
|
276
|
+
### Performance
|
|
277
|
+
- **CPU_L**: Small datasets (< 1M records)
|
|
278
|
+
- **CPU_2XL**: Medium datasets (1M-10M records)
|
|
279
|
+
- **CPU_4XL**: Large datasets (> 10M records)
|
|
280
|
+
|
|
281
|
+
### Security
|
|
282
|
+
1. No hardcoded credentials β use SF CLI authentication only
|
|
283
|
+
2. Validate input data β check for nulls and data types
|
|
284
|
+
3. Limit write permissions β only grant necessary DLO/DMO access
|
|
285
|
+
|
|
286
|
+
## Integration with Other Skills
|
|
287
|
+
|
|
288
|
+
**Use with getting-datacloud-schema skill (CRITICAL for validation):**
|
|
289
|
+
|
|
290
|
+
The `getting-datacloud-schema` skill is **required** for validating DLOs before testing code extensions.
|
|
291
|
+
|
|
292
|
+
**Use with Datakit Workflow:**
|
|
293
|
+
1. Create DLO via code extension
|
|
294
|
+
2. Map DLO to DMO using datakit workflow
|
|
295
|
+
3. Use DMO in segments and activations
|
|
296
|
+
|
|
297
|
+
## Command Reference
|
|
298
|
+
|
|
299
|
+
| Command | Purpose | Required Args |
|
|
300
|
+
|---------|---------|---------------|
|
|
301
|
+
| `script init` | Create new script project | --package-dir |
|
|
302
|
+
| `function init` | Create new function project | --package-dir |
|
|
303
|
+
| `script scan` | Generate config | entrypoint file |
|
|
304
|
+
| `script run` | Test locally | entrypoint file, --target-org |
|
|
305
|
+
| `script deploy` | Deploy to Data Cloud | --target-org, --name, --package-dir, --package-version, --description |
|
|
306
|
+
|
|
307
|
+
## Resources
|
|
308
|
+
|
|
309
|
+
- SF CLI Plugin: https://github.com/salesforcecli/plugin-data-code-extension
|
|
310
|
+
- Python SDK: https://github.com/forcedotcom/datacloud-customcode-python-sdk
|
|
311
|
+
- Data Cloud Docs: https://help.salesforce.com/s/articleView?id=sf.c360_a_intro.htm
|
|
312
|
+
- Python SDK PyPI: https://pypi.org/project/salesforce-data-customcode/
|
|
313
|
+
|
|
314
|
+
## Notes
|
|
315
|
+
|
|
316
|
+
- Code extensions run in isolated Python 3.11 environment
|
|
317
|
+
- Docker is required only for deployment, not for local testing
|
|
318
|
+
- Use SF CLI authentication only (no separate credential files)
|
|
319
|
+
- Scan command auto-detects permissions from code
|
|
320
|
+
- Local run uses actual Data Cloud data (not mocked)
|
|
321
|
+
- Deployments are versioned and can be rolled back in UI
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# developing-datacloud-code-extension Skill
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
A skill that provides a complete workflow for developing, testing, and deploying custom Python code extensions to Salesforce Data Cloud using the SF CLI plugin.
|
|
6
|
+
|
|
7
|
+
## What It Does
|
|
8
|
+
|
|
9
|
+
This skill helps you create Data Cloud Code Extensions through a complete workflow:
|
|
10
|
+
|
|
11
|
+
1. **Init** - Create new code extension project with scaffolding
|
|
12
|
+
2. **Develop** - Write Python transformation logic
|
|
13
|
+
3. **Scan** - Auto-detect permissions and generate config
|
|
14
|
+
4. **Run** - Test locally against Data Cloud org
|
|
15
|
+
5. **Deploy** - Package and deploy to Data Cloud
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
**Initialize a project:**
|
|
20
|
+
```
|
|
21
|
+
"Create a new Data Cloud code extension project called employee-transform"
|
|
22
|
+
"Initialize a code extension to transform employee data"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Test locally:**
|
|
26
|
+
```
|
|
27
|
+
"Run the code extension in my-transform directory against afvibe org"
|
|
28
|
+
"Test the entrypoint.py file locally"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Scan for permissions:**
|
|
32
|
+
```
|
|
33
|
+
"Scan the entrypoint.py to generate config"
|
|
34
|
+
"Update permissions in config.json"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Deploy:**
|
|
38
|
+
```
|
|
39
|
+
"Deploy Employee_Upper code extension to afvibe"
|
|
40
|
+
"Deploy this transform with package-version 1.0.0"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Direct Command Usage
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# Initialize project
|
|
47
|
+
sf data-code-extension script init --package-dir <directory>
|
|
48
|
+
|
|
49
|
+
# Scan for permissions
|
|
50
|
+
sf data-code-extension script scan --entrypoint ./payload/entrypoint.py
|
|
51
|
+
|
|
52
|
+
# Test locally
|
|
53
|
+
sf data-code-extension script run --entrypoint ./payload/entrypoint.py --target-org <org_alias>
|
|
54
|
+
|
|
55
|
+
# Deploy
|
|
56
|
+
sf data-code-extension script deploy --target-org <org_alias> --name <name> --package-version <version> --description <description> --package-dir ./payload
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Prerequisites
|
|
60
|
+
|
|
61
|
+
1. **SF CLI with Plugin**
|
|
62
|
+
```bash
|
|
63
|
+
sf plugins install @salesforce/plugin-data-codeextension
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. **Python 3.11**
|
|
67
|
+
```bash
|
|
68
|
+
python --version # Must be 3.11.x
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
3. **Data Cloud Custom Code SDK**
|
|
72
|
+
```bash
|
|
73
|
+
pip install salesforce-data-customcode
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
4. **Docker** (for deploy only)
|
|
77
|
+
- Docker Desktop or equivalent
|
|
78
|
+
|
|
79
|
+
5. **Authenticated Org**
|
|
80
|
+
```bash
|
|
81
|
+
sf org login web --alias <org_alias>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Quick Start
|
|
85
|
+
|
|
86
|
+
### Complete End-to-End Example
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Create project
|
|
90
|
+
mkdir employee-transform && cd employee-transform
|
|
91
|
+
sf data-code-extension script init --package-dir .
|
|
92
|
+
|
|
93
|
+
# 2. Edit payload/entrypoint.py with your transformation
|
|
94
|
+
|
|
95
|
+
# 3. Scan for permissions
|
|
96
|
+
sf data-code-extension script scan --entrypoint ./payload/entrypoint.py
|
|
97
|
+
|
|
98
|
+
# 4. Test locally
|
|
99
|
+
sf data-code-extension script run --entrypoint ./payload/entrypoint.py --target-org afvibe
|
|
100
|
+
|
|
101
|
+
# 5. Deploy (MUST include --package-dir ./payload)
|
|
102
|
+
sf data-code-extension script deploy \
|
|
103
|
+
--target-org afvibe \
|
|
104
|
+
--name Employee_Upper \
|
|
105
|
+
--package-version 1.0.0 \
|
|
106
|
+
--description "Uppercase employee positions" \
|
|
107
|
+
--package-dir ./payload
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Example Transformation
|
|
111
|
+
|
|
112
|
+
**Read from DLO, transform, write to DLO:**
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from datacustomcode import Client
|
|
116
|
+
|
|
117
|
+
client = Client()
|
|
118
|
+
|
|
119
|
+
# Read employee data from DLO
|
|
120
|
+
employees = client.read_dlo('Employee__dll')
|
|
121
|
+
|
|
122
|
+
# Transform - uppercase position field
|
|
123
|
+
employees['position_upper'] = employees['position'].str.upper()
|
|
124
|
+
|
|
125
|
+
# Select output columns
|
|
126
|
+
output = employees[['id', 'name', 'position_upper']]
|
|
127
|
+
|
|
128
|
+
# Write to output DLO
|
|
129
|
+
client.write_to_dlo('Employee_Upper__dll', output, 'overwrite')
|
|
130
|
+
|
|
131
|
+
print(f"Processed {len(output)} employee records")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Project Structure
|
|
135
|
+
|
|
136
|
+
After `init`, you'll have:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
my-transform/
|
|
140
|
+
βββ payload/
|
|
141
|
+
β βββ entrypoint.py # Your transformation code
|
|
142
|
+
β βββ config.json # Permissions and configuration
|
|
143
|
+
βββ requirements.txt # Python dependencies
|
|
144
|
+
βββ README.md
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Common Operations
|
|
148
|
+
|
|
149
|
+
### Read/Write DLOs
|
|
150
|
+
```python
|
|
151
|
+
# Read
|
|
152
|
+
df = client.read_dlo('Employee__dll')
|
|
153
|
+
|
|
154
|
+
# Write (modes: 'overwrite', 'append')
|
|
155
|
+
client.write_to_dlo('Employee_Upper__dll', df, 'overwrite')
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Read/Write DMOs
|
|
159
|
+
```python
|
|
160
|
+
# Read
|
|
161
|
+
df = client.read_dmo('EmployeeDMO')
|
|
162
|
+
|
|
163
|
+
# Write (modes: 'upsert', 'insert')
|
|
164
|
+
client.write_to_dmo('EmployeeDMO', df, 'upsert')
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Troubleshooting
|
|
168
|
+
|
|
169
|
+
| Error | Quick Fix |
|
|
170
|
+
|-------|-----------|
|
|
171
|
+
| Plugin not found | `sf plugins install @salesforce/plugin-data-codeextension` |
|
|
172
|
+
| Python SDK missing | `pip install salesforce-data-customcode` |
|
|
173
|
+
| Wrong Python version | Use pyenv to install 3.11.0 |
|
|
174
|
+
| Org not connected | `sf org login web --alias <alias>` |
|
|
175
|
+
| Config missing | Run scan command |
|
|
176
|
+
| DLO not found | Check DLO name, use getting-datacloud-schema skill |
|
|
177
|
+
| Docker error | Start Docker Desktop |
|
|
178
|
+
|
|
179
|
+
## CPU Size Selection
|
|
180
|
+
|
|
181
|
+
| CPU Size | Use Case | Data Volume |
|
|
182
|
+
|----------|----------|-------------|
|
|
183
|
+
| CPU_L | Small datasets | < 1M records |
|
|
184
|
+
| CPU_XL | Medium datasets | 1M-5M records |
|
|
185
|
+
| CPU_2XL | Large datasets (default) | 5M-10M records |
|
|
186
|
+
| CPU_4XL | Very large datasets | > 10M records |
|
|
187
|
+
|
|
188
|
+
## Resources
|
|
189
|
+
|
|
190
|
+
- **SF CLI Plugin**: https://github.com/salesforcecli/plugin-data-code-extension
|
|
191
|
+
- **Python SDK**: https://github.com/forcedotcom/datacloud-customcode-python-sdk
|
|
192
|
+
- **Data Cloud Docs**: https://help.salesforce.com/s/articleView?id=sf.c360_a_intro.htm
|
|
193
|
+
- **SDK on PyPI**: https://pypi.org/project/salesforce-data-customcode/
|