Deploy a Function

Now that you’ve developed and tested your function locally, deploy your project so you can invoke your function from your Salesforce org. The first time a Salesforce Functions project is deployed, the upload can be 500 MB or more.

Add Project to Git

Before you deploy, commit your functions code changes to a git repo. The deploy process uses changes tracked in git to know what to deploy. Since you just created this project, add the project to a new repo.

From the root directory of your project, use the following git commands:

git init
git add .
git commit -m "Initial project commit after project creation"

At this point you can optionally push your changes to github.com, but it isn't required for deploying a function.

Your project is now ready to deploy. If you make additional changes to your function code, use git add and git commit to commit those changes to the repo before deploying again.

For more details on adding your repo to github.com, see Create a repo.

Deploy Function to Compute Environment

To deploy your project's function, use the following command with the scratch org alias we created earlier.

sf deploy functions -o MyOrgAlias

The deploy process can take several minutes.

To check the status of your deployed project, use sf env list.

sf env list
Salesforce Orgs
============================================================================================================================================
| Aliases Username                                         Org ID             Instance Url                        Auth Method Config
| ─────── ──────────────────────────────────────────────── ────────────────── ─────────────────────────────────── ─────────── ──────────────
|         functionsuser@salesforce-developers.com          00D3h000000Gr9mEAC https://na111.salesforce.com        web
| DevHub  myuserfunctions@salesforce.com                   00D5e000002URZtEAO https://user-dev-ed.my.salesforce.… web
| d16673… myuser1234@d16673dc-20210803-functions-trial.com 00D5e000003TQoSEAW https://d16673dc-20210803-function… web         target-dev-hub
| Bob_De… bob@ding.dong                                    00DB0000000KfREMA0 https://fc2bfda2-20210913-function… web
| Prod_O… alan@ding.dong                                   00DB0000000KfREMA0 https://fc2bfda2-20210913-function… web

Scratch Orgs
==========================================================================================================================================
| Aliases Username                      Org ID             Instance Url                                                 Auth Method Config
| ─────── ───────────────────────────── ────────────────── ──────────────────────────────────────────────────────────── ─────────── ──────
|         test-15zzduduspjn@example.com 00D3D000000BJJLUA4 https://mycompany.scratch.my.salesforce.com                  web

Compute Environments
============================================================================================================
| Alias         Project Name            Connected Org Alias Connected Org Id   Compute Environment Name
| ───────────── ─────────────────────── ─────────────────── ────────────────── ─────────────────────────────
| Prod_Env_Alan GA_Bug_Bash_Prod_Manual Prod_Org_Alan       00DB0000000KfREMA0 ga-bug-00db0000000kfrema0-203

For more details on deploying projects, see the Salesforce Functions Developer Guide.