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, you need to configure your org to work with Salesforce Functions, create a compute environment, and associate it with your org.

Enable Functions on Dev Hub Orgs

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.

Note this is a one-time step that you'll perform on your Dev Hub org. After enabling Functions in your Dev Hub org, any scratch or sandbox orgs created from this Dev Hub org will automatically have Functions enabled and authenticated.

To authenticate Salesforce Functions in your Dev Hub org, go to Setup and in the Quick Find box search for "Functions". Select the Functions setup page.

Functions Setup screenshot

This setup page is only available in orgs that have Lightning Experience enabled, not Salesforce Classic.

Click Enable Functions in the Functions setup page to start creating the authenticated connection between your org and Salesforce Functions. A Salesforce sign-in browser window will open requesting your Salesforce Functions login information.

For beta, use the same credentials as your DevHub admin login credentials, or the Salesforce Functions account credentials provided to you by Salesforce.

After you’ve entered your Salesforce Functions login credentials, the connection process will complete. This can take up to a couple minutes. When the process successfully finishes, the Enable Functions button will no longer be present, and information about the connected Salesforce Functions account will be displayed in the Functions setup page.

Functions connected screenshot

If the connection process is not successful, error information will be displayed in the Functions setup page. You may attempt the process again by clicking Try Again, or contact Salesforce for help.

Note that when you first connect your org with Salesforce Functions, a "Functions" permission set is created automatically. See Function Permissions for more details about this permission set.

Once your Dev Hub org is authenticated with Salesforce Functions, you can create compute environments connected to your Dev Hub org, or scratch or sandbox orgs created from your Dev Hub org. You can then deploy Functions to these compute environments and invoke them from the connected orgs.

If you have sandbox orgs that you created from your Dev Hub org before you enabled Functions, those sandbox orgs will not automatically be enabled for Functions. You'll need to access the Functions setup page as described earlier in those sandbox orgs and enable Functions for each sandbox 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 Compute Environment for 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.

For the Functions beta, compute environments can only be created for sandbox, scratch, or trial orgs

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

Currently env:create:compute requires providing an org alias. The command won't automatically use the current default target org in your CLI session.

List Compute Environments

To check which compute environments you've created, use the 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 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 force:org:create CLI command:

If your current default Dev Hub org isn't the Dev Hub that has Functions enabled, you'll need to 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

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

After creating your scratch org, if you need to access your scratch org (to add data records for testing, for example) use the sfdx force:org:open CLI command to log in to your scratch org in a browser window.

Note that scratch orgs by default expire after 7 days, and the Salesforce Functions does not currently automatically remove compute environments for expired orgs, so you'll need to manually delete compute environments for those orgs.

For more information on scratch orgs, see Scratch Orgs.

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 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.