Create a Salesforce Function
You're ready to create your first function. Run this command in the project root directory:
-nthe name of the function; must start with a letter and contain only lowercase letters and numbers
-lthe programming language for your function;
Your project now contains the basic scaffolding for your function, including supporting metadata and default boilerplate code. The project generation process creates a directory
myfunction with default configuration files:
package.jsonfile that contains information about dependencies
project.tomlfile that contains function metadata information. See Developer Guide: Function Metadata TOML Files for more details.
index.jsthat contains boilerplate code for your function. This file is your primary source code file. It's preconfigured with an entry point method that has parameters used to pass payload data to the function and to communicate with the invoking org. The default function in
index.jslogs the received payload, issues a query for Account data, and logs the query results.
The function parameters are:
|event||An Event object that describes the triggering event and contains event data. This parameter is also sometimes called the 'payload.'|
|context||Salesforce org context for reading from and writing to Salesforce. The context is pre-configured to be authenticated to the invoking org.|
|logger||Salesforce logger for the function.|
index.js and update your function to match the following example. This function uses the Salesforce Functions SDK for Node.js to insert a new Account record in your scratch org. It then queries all Account records with the given fields in the org. The new Account's name is populated from the
name field of the payload.