Create a Scratch Org and Compute Environment

A scratch org is a source-driven and disposable deployment of Salesforce code and metadata. You'll use a scratch org to do your Salesforce Functions development and local testing.

Deployed Functions run in a compute environment in the Salesforce cloud. When you create a compute environment, you specify an org that the compute environment is associated with. That org can access and invoke Functions deployed to that compute environment.

Create a Scratch Org

Switch to your project’s root directory.

Verify that the config/project-scratch-def.json file enables the Functions feature. We'll use this configuration to create a Scratch Org.

Run this command in your project's root directory:

  • -s set the created org as the default
  • -f path to the scratch org definition file
  • -a set an alias for the created scratch org
  • -v link to your DevHub

See sfdx force:org:create --help for information on options.

See Scratch Orgs for more information.

In VS Code, from the Command Palette, select SFDX: Create a Default Scratch Org.... Select the project-scratch-def.json file. Enter the alias MyScratchOrgAlias. Select the default number of days until expiration.

Create a Compute Environment

After creating the scratch org, create a Salesforce compute environment that's associated with the scratch org. Your functions deploy to this compute environment.

  • -o Alias of the org the compute environment is connected to.
  • -a Alias for the newly created compute environment.