Get to Know Salesforce Functions
After completing this unit, you’ll be able to:
- Explain what Salesforce Functions do.
- Decide when to use a function.
- Find what you need to create and deploy a function.
Discover Salesforce Functions
Use Salesforce Functions to build and integrate individual blocks of logic which extend your apps using the languages and tools of your choice. You write code that performs a specific task on trusted, managed Salesforce infrastructure, preauthenticated and preconfigured to use Salesforce data. Apex code, or a low-code solution such as a Salesforce Flow, then invokes your code on demand. Your function automatically scales to meet the load. Since Salesforce Functions is built and managed by Salesforce, this frees your app design from the API limits encountered by off-platform solutions.
Your function is automatically authenticated to the org invoking the function at run-time, meaning that you don’t have to worry about dealing with authentication or other external system access complexity.
With Salesforce Functions, perform compute-heavy tasks that were previously challenging to do in your org. Salesforce elastically scales compute resources for your functions. This means you don’t manually have to modify compute resource configurations whenever you update a function. The functions are written with open languages and tools, and run on our platform with preconfigured secure access to Customer 360 data.
When to Use Salesforce Functions
Salesforce Functions use cases include:
- Complex business calculations, such as loan processing, managing product license keys, contract billing, and demand forecasting
- Batch processing, such as daily inventory stocking, consumer goods assortments, ERP calculations, and material resource planning
- Resource-intensive back-office automation, such as document generation, mail merges, invoice creation, payroll processing, QR codes, and case routing
Pick and choose which compute tasks you want to manage with Salesforce Functions. Quickly deliver computation-heavy workloads by invoking a function using Apex or a low-code solution.
Once you see how effective your first function is, you’ll likely want to create more. And if you keep your programming centralized, it’s easier to maintain and deploy changes as part of your own continuous integration and continuous deployment (CI/CD) environment.
How Salesforce Functions Work
A function is your code, run on-demand, in Salesforce Functions elastic compute environments. Once you add functions to your Salesforce projects for your complex business logic code, Salesforce Functions takes care of everything else necessary to invoke your code in a secure and self-scaling environment.
The Functions developer workflow typically involves the following steps.
Use your favorite development environment on your local workstation. We suggest VS Code, and we provide VS Code extensions to help you along.
Or you can use what you like with the Salesforce CLI. Once you’re ready to test, you can run your function locally and validate using scratch or sandbox orgs.
- Deploy your function to the Salesforce Functions infrastructure.
Use Salesforce Functions compute environments to manage your function’s application lifecycle. Integrate Salesforce Functions as part of your SFDX projects into your CI/CD system as needed.
- Invoke your deployed Function in your sandbox or production orgs.
Use Apex to securely offload heavy compute tasks to your functions without worrying about Salesforce org limits. Through Apex, you can include function invocation in your Salesforce application workflow via Flow, Lightning Web Components, or many other Salesforce features that can be extended with Apex to invoke your function.
What You Need to Create and Deploy a Function
Here’s the basic process for creating and deploying a function.
- A Salesforce Functions license is required to enable functions for your DevHub org. Contact your Salesforce account representative for steps to acquire the license.
- Set up a Developer Hub (DevHub) to create and manage scratch orgs. The scratch org is a source-driven and disposable deployment of Salesforce code and metadata, made for developers and automation.
- Develop Functions locally. You can use the Salesforce CLI in conjunction with a text editor or IDE of your choice or VS Code and the extensions we provide.
- Run, test, and debug locally while connected to a scratch org or sandbox.
- Deploy function(s) using the command line.
It’s now ready. You invoke it from an Apex class within an org.