Use JavaScript and TypeScript Functions

If you’re developing your function using JavaScript or TypeScript, here are some considerations to keep in mind.

Use the Salesforce SDK for Node.js Functions 

Salesforce provides the Salesforce SDK for Node.js Functions specifically for functions written in TypeScript. This SDK provides classes to securely and efficiently access Salesforce org resources.

Salesforce SDK isn’t needed for JavaScript development.

Note

See Salesforce SDK for Node.js Functions.

Set and Access Environment Variables 

Use the Salesforce CLI to set environment variables in your functions compute environments, and then access them in your JavaScript function code as regular system variables. See Environment Variables for more details.

Objects and JSON 

Input 

When your Javascript function runs, Salesforce Functions handles converting JSON data into a Javascript object.

For example, if your function accepts JSON input like:

1{
2  "fieldOne": "Hello World!",
3  "fieldTwo": 23
4}

Salesforce Functions converts it into a Javascript object:

1const input = {
2  fieldOne: "Hello World!",
3  fieldTwo: 23
4};

Output 

You must ensure that Javascript functions return objects that can be serialized to JSON.

Utilize Logs 

A Logger instance is provided to JavaScript functions at invoke-time. For more details on using this instance see Generate Log Information in Your Function Code.

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.