Explore Solutions and Sample Code
Get help using Salesforce Functions to solve specific problems.
Our library of solutions covers all aspects of creating and working with Salesforce Functions. Many solutions include links to sample code that you can use as a starting point for your function development.
Check out these GitHub repositories, which contain Salesforce Functions recipes.
- Functions Recipes
- eCars Sample
- Salesforce PDF Generator
- Accounts Sync App
- PostgreSQL for Node.js
- PostgreSQL for Java
- Redis for Node.js
- Redis for Java
Use the Salesforce SDKs, along with other standard Salesforce APIs, to access org resources.
- Developer Guide: Access Salesforce Resources Best practices around accessing Salesforce resources.
- Reference: Salesforce SDK for Node.js Functions Reference documentation for the classes and methods of the SDK used to develop TypeScript functions.
- Reference: Salesforce SDK for Java Functions Reference documentation for the classes and methods of the SDK used to develop Java functions.
- Sample: SalesforceSDK_JS A JavaScript sample function that uses the SDK to insert and query records.
- Sample: SalesforceSDK_Java A Java sample function that uses the SDK to insert and query records.
Functions, unlike Apex, don't automatically handle data transactions for you. Transactions ensure that all related data changes are made at the same time and that they can be undone if necessary. To manage transactions in a function, use the UnitOfWork
SDK class.
- Developer Guide: Access Salesforce Resources Best practices around accessing Salesforce resources using
UnitOfWork
. - Developer Guide: Apex Patterns If you're used to how transactions work in Apex, see this document for how to transition to creating your own transactions with the SDK.
- Reference: Node.js SDK UnitOfWork class Reference documentation on the Node.js SDK
UnitOfWork
class. - Reference: Java SDK UnitOfWork class Reference documentation on the Java SDK
UnitOfWork
class. - Sample: UnitOfWork_JS A JavaScript sample function that shows how to use
UnitOfWork
to define your own transactions. - Sample: UnitOfWork_Java A Java sample function that shows how to use
UnitOfWork
to define your own transactions.
Use JavaScript or TypeScript along with your favorite Node frameworks to build a function that your org can invoke.
- Set Up Your Development Environment Set up your dev environment to develop JavaScript functions.
- Developer Guide: Develop a Function Details about creating JavaScript functions, adding dependencies, specifying a function entry point, and more.
- Developer Guide: JavaScript Functions JavaScript-specific information for developing functions – debugging, testing, logging and more.
- Reference: Salesforce SDK for Node.js Functions Reference documentation for the SDK you use to develop JavaScript and TypeScript functions.
- Sample: JavaScript samples Sample JavaScript functions (in directories ending with "_JS").
Use Java and your favorite Java frameworks to build a function that your org can invoke.
- Set Up Your Dev Environment Set up your dev environment to develop Java functions.
- Developer Guide: Develop a Function Detailed information about creating Java functions, adding dependencies, specifying the function entry point, and more.
- Developer Guide: Java Functions Java-specific information for developing functions – debugging, testing, logging, and more.
- Reference: Java SDK Reference documentation for the Salesforce SDK for Java functions.
- Sample: Java samples Sample Java functions (in directories ending with
\_Java
).
Do you have Apex code that is hitting Apex compute limits? Transition your Apex code to a function using patterns and best practices, and take advantage of elastic auto-scaling in Salesforce Functions compute environments.
- Developer Guide: Functions Patterns for Apex Developers Development patterns and best practices for Apex developers developing functions.
- Developer Guide: Limits Understand how Salesforce Functions limits compare to Apex limits.
- Developer Guide: Permissions Understand how Salesforce Functions object permissions compare to Apex permissions.
Before you deploy your function, you can run and debug it locally.
- Developer Guide: Local Invocation Steps for starting your function locally, and invoking it.
- Developer Guide: Use Logs to Debug Debug your function via logs.
Learn how to integrate your function code and function invocation code in your testing pipeline.
- Developer Guide: Test and Validate Functions Best practices for testing functions.
- Developer Guide: Development and Application Lifecycle Workflow Details about automating function testing.
- Sample: UnitOfWork_JS A JavaScript sample that shows how to use, mock, and test
UnitOfWork
. - Sample: UnitOfWork_Java A Java sample that shows how to use, mock, and test
UnitOfWork
.
Like any Salesforce org custom development, you need to manage how and where functions are tested and deployed. Functions compute environments are tied to orgs, helping you avoid deploying an in-development function to a production org.
- Developer Guide: Development and Application Lifecycle Workflow Details about automating function testing.
Before a Function can be invoked from a Salesforce org, it must be deployed to a Salesforce Functions compute environment associated with the org.
- Overview Understanding Salesforce Functions projects and compute environments.
- Developer Guide: Deploy a Function Steps for connecting an org with Salesforce Functions, creating compute environments, and deploying function projects to compute environments.
Salesforce makes it easy to invoke a deployed function from your org, using Salesforce features you're already familiar with, like Apex. You can invoke a function from your org synchronously or asynchronously as easily as calling an Apex method.
- Developer Guide: Deploy Function Invocation Using Apex Steps for invoking your deployed function from Apex, synchronously and asynchronously.
- Apex Reference Guide: Functions namespace Reference documentation for the
Functions
Apex namespace used to invoke functions from Apex synchronously or asynchronously. Includes examples of mocking a function invocation.
When invoked, functions use specific permission sets for data access. Understand what permissions you can set, which permission sets to use, and what user role runs the functions.
- Developer Guide: Function Permissions Details on the Functions permission sets.