Salesforce Functions API
An open-source API specification for Salesforce Functions
Last updated
An open-source API specification for Salesforce Functions
Last updated
Goal
Apex Functions support for server SDK developed in ANY programming language hosted in ANY infrastructure, be it local or cloud.
Develop an open standard so anyone can develop a server SDK on any programming language and deploy it to any cloud provider. This can be open source or commercial.
Salesforce to Provide
Provide a set of Apex interfaces. Keep them compatible with the current SF Function implementation.
Provide the message structures (JSON Schema) that will be used to communicate between SF Function and the server
Provide a set of Testing assets to test the implementation to ensure they meet the standards. These will be Apex and also Postman projects.
Server Side SDK provider to provide at a minimum.
Support the Functions messaging standard.
Request-Reply support (1:1)
Call back support (1:1 and 1:M)
Ability to perform CRUD on Salesforce object
Pass the Apex Functions confirmation Test.
Server SDK Setup
The server should provide an HTTPS endpoint that can accept a POST, and the URI will be /functions.
POST
https://api.apexfunctions.com/functions
GET
https://api.apexfunctions.com/functions
(Need to define a JSON Format)
String
Use the Function Apex class to access deployed Salesforce Functions and invoke them synchronously or asynchronously.
This is the primary class all users will use. The sample code will look as follows.
Note the line Function.get('MyProject.AccountFunction'); The value we are passing MyProject.AccountFunction.
AccountFunction
is the name of the function that is passed to the server.
Request JSON (Work in Progress)
userSessionId
userName
type
timeStamp
specversion
source
orgId
id
datacontenttype
data_base64
Do we need this ?
data
Response JSON (Work in Progress)
userName
totalTime
timeCompleted
serverName
source
orgId
invocationid
This should be id but that is a reserved word in SF
function
error
response
SF Function can be invoked asynchronously. For this, the calling Apex Code will implement
The following sample code shows how this is done in Apex
1:1 Callbacks: These are callbacks when a request is completed
1:N Callbacks: These are callbacks that are made during the execution of a function.
Server side SDK
Salesforce object name
Name
String
The ID of the function call
Status
String
ERROR, PENDING, SUCCESS
Response
String
Response as a JSON Striong
ResponseType
String
JSON or Base64
CallBackClass
String
The name of the Apex Callback Class
The client-server communication is based on open standards (); thus, any Cloud Events client can use the server application you have written. Cloud Events provides SDKs for Go, JavaScript, Java, C#, Ruby, PHP, PowerShell, Rust, and Python.
MyProject is the name of the if the URL is set to https://api.apexfunctions.com/ in a named credential called "MyProject" The callout will look like
Represents the callback Salesforce calls when an asynchronous, queued Function invocation has been completed.
Represents the error type of FunctionInvocationError.
Use FunctionInvocation to get the status and results of a synchronous or asynchronous Function invocation.
Use FunctionInvocationError to get detailed error information about a failed Function invocation.
Represents the status of a Function invocation.
Use the FunctionInvokeMock interface to mock Salesforce Functions responses during testing.
Use the MockFunctionInvocationFactory methods to generate appropriate mock responses for testing Salesforce Functions.