Create a Scratch Org

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

  1. Check that the config/project-scratch-def.json file in your project has the "Functions" feature enabled:

The values in this file indicate that the scratch org you’ll create is a Developer Edition org with the Functions feature turned on.

  1. From the command palette run the command: SFDX: Create a Default Scratch Org...

    a. Select the project-scratch-def.json file for your Functions project

    b. Enter an org alias ("MyScratchOrgAlias")

    c. Select or enter the default number of days until expiration.

After your scratch org is successfully created, you’ll see a Success message. The scratch org is now listed as the default org in the bottom panel in VS Code -- this means that all the future org commands are directed at this scratch org.

Create Salesforce Compute Environment for Scratch Org

After creating the scratch org, you need to create a Salesforce compute environment that is associated with the scratch org. This compute environment is where your Functions will get deployed to.

In the VS Code terminal, use the following command to create the compute environment:

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