Newer Version Available

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

MockFunctionInvocationFactory Class

Use the MockFunctionInvocationFactory methods to generate appropriate mock responses for testing Salesforce Functions.

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, the 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.

See FunctionInvokeMock Example Implementation.

MockFunctionInvocationFactory Methods

The following are methods for MockFunctionInvocationFactory.

createErrorResponse(invocationId, functionsErrorType, errMsg)

Generate a response for an error condition during mock testing of Salesforce Functions.

Signature

public static functions.FunctionInvocation createErrorResponse(String invocationId, functions.FunctionErrorType functionsErrorType, String errMsg)

Parameters

invocationId
Type: String
The ID associated with a call to either the synchronous or asynchronous Function.invoke() method.
functionsErrorType
Type: FunctionErrorType Enum
The error type of FunctionInvocationError.
errMsg
Type: String
The error message.

Return Value

Type: FunctionInvocation Interface

createSuccessResponse(invocationId, response)

Generate a response for a successful mock test of Salesforce Functions.

Signature

public static functions.FunctionInvocation createSuccessResponse(String invocationId, String response)

Parameters

invocationId
Type: String
The ID associated with a call to either the synchronous or asynchronous Function.invoke() method.
response
Type: String
The message indicating success.

Return Value

Type: FunctionInvocation Interface