Terminal
Terminal/Skill
Scaffolds, tests, scans and deploys Python code extensions that transform Data Cloud data lake and model objects.
By Salesforce
Works with
npx skills add forcedotcom/sf-skills --skill data360-code-extension-generateThis 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).
Before executing any code extension commands, verify prerequisites:
SF CLI with plugin installed
sf plugins --core | grep data-code-extension
If not installed:
sf plugins install @salesforce/plugin-data-code-extension
Python 3.11
python --version # Should show 3.11.x
Data Cloud Custom Code SDK
pip list | grep salesforce-data-customcode
If not installed:
pip install salesforce-data-customcode
Docker running (for deploy only)
docker ps
Authenticated org
sf org display --target-org <org_alias> --json
Create a new code extension project with scaffolding.
Commands:
For script-based code extensions (batch transformations):
sf data-code-extension script init --package-dir <directory>
For function-based code extensions (real-time):
sf data-code-extension function init --package-dir <directory>
Required Option:
--package-dir, -p - Directory path where the package will be createdWhat it creates:
my-transform/ # Project root
├── payload/ # CRITICAL: This is what --package-dir must point to for deploy
│ ├── entrypoint.py # Main transformation code
│ └── config.json # Code extension configuration
├── requirements.txt # Python dependencies
└── README.md
IMPORTANT: Understanding the directory structure is critical for successful deployment.
Commands and their directory requirements:
| Command | Run From | Path/File Argument |
|---|---|---|
init | Parent directory | <project-name> or . |
scan | Project root | ./payload/entrypoint.py |
run | Project root | ./payload/entrypoint.py |
deploy | Project root | --package-dir ./payload (REQUIRED) |
CRITICAL: The --package-dir argument in deploy command MUST point to the payload directory, not the project root.
Edit payload/entrypoint.py with transformation logic.
Script Example (Batch):
from datacustomcode import Client
client = Client()
# Read from DLO
df = client.read_dlo('Employee__dll')
# Transform data (uppercase position field)
df['position_upper'] = df['position'].str.upper()
# Write to output DLO
client.write_to_dlo('Employee_Upper__dll', df, 'overwrite')
Function Example (Real-time):
from datacustomcode import FunctionClient
def transform(event, context):
client = FunctionClient(context)
input_data = event['data']
output = {
'name': input_data['name'].upper(),
'status': 'processed'
}
return output
Common Operations:
client.read_dlo('DLO_Name__dll') - Read from DLOclient.read_dmo('DMO_Name') - Read from DMOclient.write_to_dlo('DLO_Name__dll', df, 'overwrite') - Write to DLOclient.write_to_dmo('DMO_Name', df, 'upsert') - Write to DMOScan the entrypoint file to detect required permissions and generate config.json.
Command:
sf data-code-extension script scan --entrypoint ./payload/entrypoint.py
What it detects:
config.json and requirements.txtCRITICAL: Before running tests locally, validate that all DLOs used in your code exist and have the expected fields.
After scanning, review the generated config.json to identify all DLOs:
cat payload/config.json
Use the data360-schema-get skill to verify DLOs exist and check field names.
For each DLO referenced in your code:
Verify DLO exists:
python3 scripts/get_dlo_schema.py <org_alias> <dlo_name>
Verify field names match — compare fields used in your entrypoint.py against the DLO schema.
Check all DLOs:
read permissionswrite permissionsBefore proceeding to run, ensure:
After validating DLO schemas, run the code extension locally against your Data Cloud org.
Command:
sf data-code-extension script run --entrypoint <entrypoint_file> --target-org <org_alias> [options]
Options:
--target-org, -o - SF CLI org alias (required)--config-file, -c - Custom config file pathIf you get errors:
Deploy the code extension to Data Cloud for scheduled or on-demand execution.
CRITICAL: You MUST specify --package-dir ./payload to point to the payload directory created by init.
Command:
sf data-code-extension script deploy --target-org <org_alias> --name <name> --package-dir ./payload --package-version <version> --description <description> [options]
Required Options:
--target-org, -o - SF CLI org alias--name, -n - Name for code extension deployment--package-dir - Path to payload directory (REQUIRED - must be ./payload when running from project root)--package-version - Version string (default: 0.0.1)--description - Description of code extensionOptional Options:
--cpu-size - CPU size: CPU_L, CPU_XL, CPU_2XL (default), CPU_4XL--function-invoke-opt - Function invoke options (for function type)--network - Docker network (default: default)After deployment:
| Error | Solution |
|---|---|
command data-code-extension not found | sf plugins install @salesforce/plugin-data-code-extension |
datacustomcode CLI not found | pip install salesforce-data-customcode |
Python version mismatch | Use pyenv: pyenv install 3.11.0 && pyenv local 3.11.0 |
Cannot connect to Docker daemon | Start Docker Desktop |
No org found for alias | sf org login web --alias <org_alias> |
config.json not found | sf data-code-extension script scan --entrypoint ./payload/entrypoint.py |
DLO not found | Verify DLO exists (use data360-schema-get skill), check spelling and __dll suffix |
Permission denied writing | Re-run scan, verify target DLO exists and is writable |
Deploy fails - wrong directory | Ensure --package-dir points to payload/ directory, not project root |
run command before deploying--package-dir ./payloadUse with data360-schema-get skill (CRITICAL for validation):
The data360-schema-get skill is required for validating DLOs before testing code extensions.
Use with Datakit Workflow:
| Command | Purpose | Required Args |
|---|---|---|
script init | Create new script project | --package-dir |
function init | Create new function project | --package-dir |
script scan | Generate config | entrypoint file |
script run | Test locally | entrypoint file, --target-org |
script deploy | Deploy to Data Cloud | --target-org, --name, --package-dir, --package-version, --description |