MockFunctionInvocationFactory Class

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

functions

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.

The following are methods for MockFunctionInvocationFactory.

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

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

  • 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.

Type: FunctionInvocation Interface

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

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

  • 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.

Type: FunctionInvocation Interface