Test a Function Locally

Test functions in your local environment before you deploy to a compute environment. Build and run your function with the Salesforce CLI and invoke it locally.

Previously, local Salesforce Functions development required using a container like Docker. Containers are no longer required to run a function locally. Learn more about Local Function Invocations.

Navigate to the function directory and build and run your function:

The function is ready to receive requests when you see Starting myfunction. The function continues to run and waits for requests until you use Ctrl-C to stop. Leave the terminal window running and open a new terminal window for the next step.

To test a running function, send it a JSON payload. Create a payload.json file in your function directory:

Navigate to your project root directory and invoke the function, which is now running on your localhost:

  • -l running function URL
  • -p the payload to send to the function

This command invokes the function running on localhost port 8080 (the default for locally running functions) with the payload JSON file. The output looks something like:

The execution logs stream in the terminal running the function (where you ran sf run function start). The output looks something like this:

To stop the function, enter Ctrl-C in the terminal window where you ran sf run function start.