Set Up Salesforce CLI for Custom Functions

Salesforce CLI, the code extension plugin, and the Data Custom Code Python SDK work together as your local toolchain for Code Extension. Use this setup to develop and test custom chunking functions locally against a sandbox and then deploy them to Data 360 for execution.

Edition Table
Available in: Developer, Enterprise, Performance, and Unlimited Editions. See Data 360 edition availability.
User Permissions Needed
To set up and use the Salesforce CLI for custom function development:Permission set:
  • Data Cloud Architect

Prerequisites 

Steps to Set Up Salesforce CLI for Custom Functions 

  1. Install Salesforce CLI version 2.130.9 or later. See Install Salesforce CLI.

  2. Confirm that your Salesforce CLI version is 2.130.9 or later:

    1sf version

    If you have an earlier version, update Salesforce CLI. See Update Salesforce CLI, and then run sf version to confirm.

  3. On Windows, install Node.js LTS and verify the installation.

    1node --version
    2npm --version
  4. Install the code extension plugin.

    1sf plugins install @salesforce/plugin-data-code-extension
  5. Make sure the installed code extension plugin version is 0.1.5 or later. If you have an earlier version, update the plugin to the latest available version.

    1sf plugins
    2sf plugins update
  6. Install the Data Custom Code Python SDK.

    macOS and Linux

    1python3.11 -m pip install salesforce-data-customcode

    Windows

    1py -3.11 -m pip install salesforce-data-customcode
  7. (Optional) Upgrade the Data Custom Code Python SDK to the latest available version.

    macOS and Linux

    1python3.11 -m pip install --upgrade salesforce-data-customcode

    Windows

    1py -3.11 -m pip install --upgrade salesforce-data-customcode
  8. Confirm the SDK installation.

    • macOS and Linux: python3.11 -m pip show salesforce-data-customcode
    • Windows: py -3.11 -m pip show salesforce-data-customcode
  9. Log in to your org. From a terminal, run one of the commands with the flags for your org type. Salesforce CLI opens your default browser for Salesforce sign-in. After you sign in, the CLI saves the session on your computer.

    • Production or Developer Edition

      1sf org login web --alias <myorg>
    • Sandbox

      1sf org login web --alias <mysandbox> --instance-url https://test.salesforce.com
    • Custom domain

      1sf org login web --alias <myorg> --instance-url https://mycompany.my.salesforce.com
  10. After you sign in, confirm which orgs the CLI is connected to and which alias you must use for code extension commands.

    1sf org list
    2sf org display --target-org <myorg>

    For example, run sf org display --target-org myorg to display the connection status of your org alias myorg.

    Running the sf org login command is a one-time setup per environment or profile. Rerun this command only if your credentials or environment details change, or if you want to set up a new profile.

    Note

  11. Create a code extension function package.

    1sf data-code-extension function init --package-dir <PACKAGE_DIR>

    Example:

    1sf data-code-extension function init --package-dir <my_package>

    Replace <my_package> with the directory name for your project, for example, my_function_package.

The command sets up the directory structure, configuration files, and dependencies for writing, testing, and deploying a custom chunking function.

1```text
2my_package/
3├── requirements.txt
4├── requirements-dev.txt
5├── Dockerfile.dependencies
6├── build_native_dependencies.sh
7├── payload/
8│   ├── config.json
9│   └── entrypoint.py
10├── .datacustomcode_proj/
11│   └── sdk_config.json
12├── .devcontainer/
13│   └── devcontainer.json
14└── README.md
15```

Here’s a summary of the directories and files in the package.

Directory or FileDescription
Dockerfile.dependenciesUsed to build dependency layers for packaging workflows.
build_native_dependencies.shHelper script to build native Python dependencies when needed.
requirements.txtLists the Python packages your function needs for deployment.
requirements-dev.txtPython packages for local development and testing only. Don’t modify this file.
payload/Contains the function and configuration that the CLI deploys to Data 360.
payload/config.jsonThe configuration manifest for a Data 360 code extension package. It defines how the function will be executed and what resources it needs.
payload/entrypoint.pyMain Python file where you implement your chunking function, for example, function(request, runtime).
.datacustomcode_proj/sdk_config.jsonProject metadata generated by the CLI, for example, type: "function".
.devcontainer/devcontainer.jsonVisual Studio Code Dev Container configuration for a consistent local environment.
README.mdPackage overview, setup notes, and how to run samples in a container or locally.

Next Step 

See Also