---
schema_version: "1"
id: 71ed712c21c0e90259fcd02e7aa9a48ad8ea88ab8786d1427ebe4676f754cde2
title: MockFunctionInvocationFactory Class
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexref/apex_class_functions_MockFunctionInvocationFactory.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_functions_MockFunctionInvocationFactory.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 247cca875b9074c6a3fac009ad1aee62b6a175e7e41e6e0c0ab3117d230b680c
description: Use the MockFunctionInvocationFactory methods to generate appropriate mock responses for testing Salesforce Functions.Generate a response for an error condition during mock testing of Salesforce Functions.Generate a response for a successful mock test of Salesforce Functions.
---
# MockFunctionInvocationFactory Class

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

## Namespace

[functions](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_namespace_functions.htm "The Functions namespace provides classes and methods used to invoke and manage Salesforce 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_functions_FunctionInvokeMock.htm#apex_interface_functions_FunctionInvokeMock_Example).

- **[MockFunctionInvocationFactory Methods](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_functions_MockFunctionInvocationFactory.htm#apex_functions_MockFunctionInvocationFactory_methods)**

## MockFunctionInvocationFactory Methods

The following are methods for MockFunctionInvocationFactory.

- **[createErrorResponse(invocationId, functionsErrorType, errMsg)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_functions_MockFunctionInvocationFactory.htm#apex_functions_MockFunctionInvocationFactory_createErrorResponse)**  
    Generate a response for an error condition during mock testing of Salesforce Functions.
- **[createSuccessResponse(invocationId, response)](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_functions_MockFunctionInvocationFactory.htm#apex_functions_MockFunctionInvocationFactory_createSuccessResponse)**  
    Generate a response for a successful mock test of Salesforce Functions.

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") The ID associated with a call to either the synchronous or asynchronous Function.invoke() method.
- **functionsErrorType**: Type: [FunctionErrorType Enum](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_functions_FunctionErrorType.htm "Represents the error type of FunctionInvocationError.") The error type of FunctionInvocationError.
- **errMsg**: Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") The error message.

#### Return Value

Type: [FunctionInvocation Interface](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_functions_FunctionInvocation.htm#apex_interface_functions_FunctionInvocation "Use FunctionInvocation to get the status and results of a synchronous or asynchronous Function invocation.")

### 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](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") The ID associated with a call to either the synchronous or asynchronous Function.invoke() method.
- **response**: Type: [String](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_string.htm#apex_methods_system_string "Contains methods for the String primitive data type.") The message indicating success.

#### Return Value

Type: [FunctionInvocation Interface](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_interface_functions_FunctionInvocation.htm#apex_interface_functions_FunctionInvocation "Use FunctionInvocation to get the status and results of a synchronous or asynchronous Function invocation.")