Newer Version Available

This content describes an older version of this product. View Latest

FunctionInvokeMock Interface

Use the FunctionInvokeMock interface to mock Salesforce Functions responses during testing.

Namespace

functions

Usage

To mock Salesforce Functions testing, implement an appropriate mock response in the respond(functionName,payload) method of the FunctionInvokeMock interface. During mock testing of a Salesforce Functions, Apex runtime sends the response specified in the respond() method, rather than invoking the function itself. Appropriate success and error messages can be configured with the createSuccessResponse(invocationId,message) and createErrorResponse(invocationId,functionsErrorType,errorMsg) methods in Functions.MockFunctionInvocationFactory.

FunctionInvokeMock Methods

The following are methods for FunctionInvokeMock.

respond(functionName, payload)

The mock response implemented in the Functions.FunctionInvokeMock interface. The response is sent by Apex runtime when the Test.setMock() method is called.

Signature

public functions.FunctionInvocation respond(String functionName, String payload)

Parameters

functionName
Type: String
The name of the Salesforce Function and the Functions Project that the Function is part of. The format of the parameter string is “project name.function name”.
payload
Type: String
The JSON-format payload data that is passed to the Function.

Return Value

Type: FunctionInvocation Interface

The result of the mock call to Salesforce Functions. Appropriate responses can be generated by using the createSuccessResponse() and createErrorResponse() methods in the Functions.MockFunctionInvocationFactory class.

FunctionInvokeMock Example Implementation

This is sample implementation of the functions.FunctionInvokeMock interface.

This example shows the minimal setup required for testing synchronous and asynchronous functions and is simplified to include both function invocations and the FunctionCallback class.