---
schema_version: "1"
id: 08e893233ea3e702c080309ddc32b6e34a7d2d65673d989a7277c247e8616ded
title: Develop Functions Using Scratch Orgs
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/salesforce-functions/functions/guide/dev-guide/scratch-orgs.md
canonical_url: https://developer.salesforce.com/docs/platform/functions/guide/scratch-orgs.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6c5fb0fb1ac68b6c936e12f7a03d9847d206e4720b622bc511876de63215e2d1
products:
  - Salesforce Functions
---
# Develop Functions Using Scratch Orgs

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.

**note:** The preferred method of developing functions is using scratch orgs. If you usually use sandbox orgs in your workflows, see our guide on how to [Develop Functions Using Sandbox Orgs](https://developer.salesforce.com/docs/platform/functions/guide/sandbox-orgs.md) instead.

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:

**config/project-scratch-def.json**

```javascript
{
"orgName": "Acme Company",
"edition": "Developer",
"features": ["Functions"]
}
```

Use your updated `project-scratch-def.json` to create a scratch org with the `sf org create scratch` CLI command:

`sf org create scratch --set-default --definition-file config/project-scratch-def.json --alias MyScratchOrgAlias`

**note:** If your current default Dev Hub org isn't the Dev Hub that has Functions enabled, specify the Functions-enabled Dev Hub org using the `--target-dev-hub` flag. For example: `sf org create scratch --set-default --definition-file config/project-scratch-def.json --alias MyScratchOrgAlias --target-dev-hub MyFcnsDevHubAlias`

To access your scratch org (to add data records for testing, for example), 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.

For more information, see [Scratch Orgs](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_scratch_orgs.htm).

**tip:** 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.
