Connect and Prepare Your Development Environment
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.
Connect to your Dev Hub, then connect to Salesforce Functions.
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.
See Configure Your Org for more information.
Login and Set an Alias To Your Dev Hub
Log in to your Dev Hub using your username and password.
-aset an alias for the authenticated org, which you use in subsequent CLI commands
-dset this org as the default org for all commands
-vset this org as the default Dev Hub for creating scratch orgs
In VS Code, from the command palette, select SFDX: Authorize a Dev Hub.
Log in to Salesforce Functions using the CLI.
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.
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:
Use your updated
project-scratch-def.json to create a scratch org via the
sfdx force:org:create CLI command:
To access your scratch org, use the
sfdx force:org:open CLI command, which logs in to your scratch org in a 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.
For more information, see 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.
After creating the scratch org, create a Salesforce compute environment that's associated with that org. Your functions deploy to this compute environment.
-oAlias of the org the compute environment is connected to
-aAlias for the newly created compute environment