Deploy a Function

Functions get deployed as part of a DX project. A project can have one or more Functions, along with org configuration (permission sets, etc) and Apex code for invocation. When you deploy your project, you'll deploy your org changes to your org, as usual, but the Functions in your project get deployed to a compute environment that you create.

If you haven't deployed to your org before, you'll need to do the following configuration steps before deploying to Salesforce Functions:

  • Connect your Dev Hub org with your Salesforce Functions account (once)
  • Connect your CLI session with your Salesforce Functions account (once per CLI session)
  • Create scratch or sandbox orgs from your Dev Hub org as needed.
  • Set up a "Functions" permission set in your project with object permissions that your Function will need and push this permission set to your scratch org or sandbox org (as needed based on what org resources your Function needs permission to)
  • Create a Compute Environment that's associated with the org you're planning to deploy to (once per Function and org combination)
  • Add your Functions project to git and commit changes

Once these steps are done, you can deploy your Function (and "Functions" permission set changes, and Apex class changes, if needed) as many times as you need to.

Connect Salesforce Functions to Your Org

Before you deploy your Function, you need to connect your org to your Salesforce Functions account. You'll do a one-time connection from your Dev Hub org to your Salesforce Functions account, and then any scratch orgs created from that Dev Hub org will automatically be associated with the same Salesforce Functions account.

See Enable Functions on Dev Hub Orgs for the steps to enable Functions in your Dev Hub org.

Connecting Your CLI Environment to Salesforce Functions

You also need to connect your CLI session to the same Salesforce Functions account you connected your Dev Hub org to. Once you’ve done this, any CLI commands that communicate with Salesforce Functions will use this authenticated session. To connect your CLI session use the following command:

This should open a browser page where you can log in to your Salesforce Functions account using the same credentials you used to connect your org.

For beta, this connection can expire after 8 hours and may need to be re-established by running sfdx login:functions again

Create the Compute Environment

A Salesforce Functions compute environment is where your Functions get deployed and run. Before you can deploy, you need a compute environment associated with your org. See Create Compute Environment for Org for the steps to create a compute environment associated with your org.

Commit Project Changes to git

Before you deploy, make sure to commit your latest project changes to git. See Add Project to git for more details on tracking your project changes with git.

Deploy to the Salesforce Functions Compute Environment

To deploy your Function project, first cd to the root directory of your DX project. Then, to deploy your project's Functions use the following command with the org alias that fits your use case (scratch org or sandbox org for development, etc). Note that the org must be already associated with a compute environment, otherwise the deploy will not succeed.

The deploy command will build and deploy your Function to Salesforce Functions, and configure the Function to be public. It can take several minutes to deploy Functions to Salesforce Functions.

Your Function code must be committed to git before you deploy, as the deploy will use the latest committed code from current git branch.

Getting a List of Deployed Functions

Use the sfdx env:list -t compute command to get a list of currently deployed Functions to compute environments:

Deployment Considerations

  • Note that initial deployments can take longer because you are uploading the full container image. Be aware of any network bandwidth restrictions (e.g. VPN or network security restrictions) you might have before deploying Functions.