Configure Orgs for Functions

Salesforce Functions are deployed to the Salesforce compute environments rather than your org. Before your org can invoke a deployed Function, configure it to work with Salesforce Functions, create a compute environment, and associate it with your org.

Enable Functions

Before your org can work with Salesforce Functions, you must enable the Salesforce Functions org setting. Doing this creates an authenticated connection for requests between your org and Salesforce Functions.

See Configure Your Org.

Enable Source Tracking for Sandboxes

If you plan on developing Functions using sandbox orgs, you should also enable Enable Source Tracking in Developer and Developer Pro Sandboxes so your team can be in synch with changes made to development sandboxes. See Enable Source Tracking in Sandboxes for more details.

Create a Compute Environment for an Org

Before you can deploy a Function, or invoke a Function from an org, you need to create a compute environment. A compute environment in the Salesforce cloud represents a place where your deployed Functions will run. When you create a compute environment, you specify an org that the compute environment will be associated with, and then that org can access and invoke Functions deployed to that compute environment.

When developing Functions, you'll most likely be creating compute environments associated with your development orgs: sandbox, or scratch orgs. Once you're ready to deploy the Function to production, you'll create a compute environment associated with your production org and deploy your Functions to that compute environment.

To create a compute environment, use the sf env create compute command, specifying the org, and optionally an alias that you can use after the compute environment has been created:

List Compute Environments

To check which compute environments you've created, use the sf env list command:

Delete Compute Environments

If you no longer need a compute environment, or you wish to dis-associate a connected org, use the sf env delete command with the compute environment alias to remove the compute environment:

Develop Functions Using Scratch Orgs

When developing your Function, use scratch orgs created from your Dev Hub org to test Salesforce data access. Scratch orgs are disposable Salesforce orgs that support development and testing. Make sure to first enable Functions in your Dev Hub org.

To create a new scratch org for your Function, first edit the config/project-scratch-def.json file in your DX project. Add the “Functions” feature:


Use your updated project-scratch-def.json to create a new scratch org via the sfdx force:org:create CLI command:

If your current default Dev Hub org isn't the Dev Hub that has Functions enabled, specify the Functions-enabled Dev Hub org using the -v argument. For example: sfdx force:org:create -s -f config/project-scratch-def.json -a MyScratchOrgAlias -v MyFcnsDevHubAlias

To access your scratch org (to add data records for testing, for example), use the sfdx force:org:open CLI command, which logs in to your scratch org in a browser window.

By default, scratch orgs expire after 7 days. Salesforce Functions doesn't remove compute environments for expired orgs, so you must manually delete compute environments for expired scratch orgs.

For more information, see Scratch Orgs.

Keep track of the scratch org alias you use—you’ll need it again when you invoke your Function. You also need it when you create the compute environment associated with your scratch org.

Develop Functions Using Sandbox Orgs

You can deploy Functions to sandbox orgs for development or testing. Sandbox orgs provide a shared environment for your team to do collaborative Function development and testing.

To create a sandbox org, you can either create it from your DevHub org UI or using the Salesforce CLI.

To create a sandbox using the Salesforce UI, see Create a Sandbox.

If you're creating the sandbox using the Salesforce CLI, you'll first create a sandbox definition file in your project's config directory, and then use sfdx force:org:create to create the org. For example, the following command creates a developer sandbox with an alias of "Dev_SB":

For more information, see Create a Sandbox Definition File and Create, Clone, or Delete a Sandbox.

After creating your sandbox org, you can confirm it's set up for Functions by logging into your newly created sandbox org and checking the information under Setup > Functions, which should match the Functions connection information from your DevHub org.