This Quick Start includes instructions for developing with scratch orgs. We recommend using a Dev Hub and scratch org for Salesforce Functions development. See Develop Functions Using Sandbox Orgs to incorporate sandbox orgs into your Salesforce Functions development.
Note
Connect to your Dev Hub, then connect to Salesforce Functions.
Connect to Your Dev Hub
The Developer Hub (Dev Hub) lets you create and manage scratch orgs. The scratch org is a source-driven and disposable deployment of Salesforce code and metadata.
Confirm Dev Hub is Enabled
In your Dev Hub org, from Setup, enter “Dev Hub” in the Quick Find box. Select Dev Hub and make sure the “Enable Dev Hub” switch is toggled on.
Log in to your Dev Hub using your username and password.
1sf org login web --set-default --alias MyDevHubAlias --set-default-dev-hub
--alias set an alias for the authenticated org, which you use in subsequent CLI commands
--set-default set this org as the default org for all commands
--set-default-dev-hub set this org as the default Dev Hub for creating scratch orgs
In VS Code, from the command palette, select SFDX: Authorize a Dev Hub.
Tip
Connect to Salesforce Functions
Log in to Salesforce Functions using the CLI.
1sf login functions
The command sf login functions opens a browser page where you can log in to your Salesforce Functions account. Use the same credentials you used to connect your Dev Hub org.
Create a Scratch Org
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 scratch org for your function, first edit the config/project-scratch-def.json file in your DX project. Add the “Functions” feature:
To access your scratch org, use the sf org open CLI command, which logs in to your scratch org in a new 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.
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.
Tip
Create a Compute Environment
After creating the scratch org, create a Salesforce compute environment that’s associated with that org. Your functions deploy to this compute environment.
1sf env create compute -o MyOrgAlias -a MyComputeEnv # use your scratch org alias
-o Alias of the org the compute environment is connected to
-a Alias for the newly created compute environment
Product Retirement Announcement
Salesforce Functions is no longer available for purchase or renewal. To preserve the capabilities that Salesforce Functions provided to your org, deploy an alternative solution before your existing order term ends. See Salesforce Functions Retirement for more information on migrating your functions. Contact your Salesforce Account Executive for more information on Heroku.