FunctionInvokeMock Interface
Use the FunctionInvokeMock interface to mock Salesforce Functions responses during testing.
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.
The following are methods for FunctionInvokeMock.
-
respond(functionName, payload)
The mock response implemented in the
Functions.FunctionInvokeMockinterface. The response is sent by Apex runtime when theTest.setMock()method is called.
The mock response implemented in the Functions.FunctionInvokeMock interface. The response is sent by Apex runtime when the Test.setMock() method is called.
public functions.FunctionInvocation respond(String functionName, String payload)
- 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.
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.
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.