# Multi-Transaction Service

The Multi-Transaction Service (MTS) is integrated with the Digital Commerce Basket APIs to split Apex transactions into multiple transactions to avoid exceeding Salesforce Governor limits. Use its configuration settings to enable it:

- [MaxCPUTimePerTransaction](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference\_148927.htm): Sets the maximum allowed CPU time per Apex transaction before the transaction is split.

- [MaxHeapSizePerTransaction](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference\_148927.htm): Sets the maximum allowed heap size per Apex transaction before the transaction is split.

- [MTSEnabled](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference\_148927.htm): Enables the Multi-Transaction Service.

- [NumberOfDMLPerTransaction](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference\_148927.htm): Sets the maximum allowed data manipulation language (DML) statements per Apex transaction before the transaction is split.

- [NumberOfQueriesPerTransaction](https://help.salesforce.com/s/articleView?id=ind.comms_t_cpq_configuration_settings_reference\_148927.htm): Sets the maximum allowed SOQL queries per Apex transaction before the transaction is split.

The MTS supports long-running transactions and returns a `multiTransactionKey` in the `nexttransaction` action. To proceed, call the API again with the `multitransactionKey` in the request payload as shown in the following example Add to Basket requests and responses with MTSEnabled set to true (the default).

**Example Requests and Responses**

Example Add to Basket Request

```nolang
POST
/services/apexrest/{namespace}/v3/catalogs/{catalog_code}/basket?contextKey=017d3c3f990567a3ce2ca3e60262ec90&context={"accountId":"0019P000024jKuZ"}&isloggedin=true

Body
{
  "offer": "TelcoResidential",
  "basketAction": "AddWithNoConfig"
}
```

Example Intermediate Response

```nolang
{
  "nexttransaction": {
    "rest": {
      "params": {
        "multiTransactionKey": "3d719d4a3b14cea4187ea9a5332cff0e",
        "method": "addWithNoConfig"
     }
    }
  }
}
```

Example Request to Pass the multiTransactionKey

```nolang
POST 
/services/apexrest/{namespace}/v3/catalogs/{catalog_code}/basket?contextKey=017d3c3f990567a3ce2ca3e60262ec90&context={"accountId":"0019P000024jKuZ"}&isloggedin=true

Body
{
  "offer": "TelcoResidential",
  "basketAction": "AddWithNoConfig",
  "multiTransactionKey": "3d719d4a3b14cea4187ea9a5332cff0e"
}

```

Example Response

This example is truncated.

```nolang
{
  "cartContextKey": "20933d86217050b8d3b15654aeceae30",
  "result": {
    "totals": {
      "EffectiveOneTimeTotal__c": 400,
      "EffectiveRecurringTotal__c": 200
    },
    "totalSize": 1,
    "records": [
      {
        "actions": {
          "deleteFromBasketAction": {
            "rest": {
              "params": {
                "basketAction": "deleteFromBasket",
                "lineItemKey": "533befb7d15a0a400f09c59ecaef21ee",
                "bundleContextKey": "533befb7d15a0a400f09c59ecaef21ee"
              },
              "link": "/v3/catalogs/vlocity_cmt/basket/20933d86217050b8d3b15654aeceae30?contextKey=017d3c3f990567a3ce2ca3e60262ec90&isloggedin=true",
              "method": "deleteFromBasketAction"
            }
          },
          "updateBasketAction": {
            "rest": {
              "params": {
                "basketAction": "updateBasket",
                "lineItemKey": "533befb7d15a0a400f09c59ecaef21ee",
                "bundleContextKey": "533befb7d15a0a400f09c59ecaef21ee"
              },
              "link": "/v3/catalogs/{catalog_code}/basket/20933d86217050b8d3b15654aeceae30?contextKey=017d3c3f990567a3ce2ca3e60262ec90&isloggedin=true",
              "method": "updateBasketAction"
            }
          }
        },
        "lineItemKey": "533befb7d15a0a400f09c59ecaef21ee",
        "bundleContextKey": "533befb7d15a0a400f09c59ecaef21ee",
        "displaySequence": -1,
        "Id": {
          "value": "8024P000001gdBNQAY",
          "previousValue": null,
          "originalValue": null,
          "messages": [],
          "label": "Order Product ID",
          "hidden": false,
          "fieldName": "Id",
          "editable": false,
          "dataType": "ID",
          "alternateValues": null,
          "actions": {}
        },
        "Pricebook2Id": "01s4P000002BoBuQAK",
        "Product2Id": "01t4P000007VDOkQAO",
        "ProductCode": "TelcoResidential",
        "UnitPrice": {
          "value": 0,
          "previousValue": null,
          "originalValue": null,
          "messages": [],
          "label": "Unit Price",
          "hidden": true,
          "fieldName": "UnitPrice",
          "editable": false,
          "dataType": "CURRENCY",
          "alternateValues": null,
          "actions": {}
        },
        "Name": "Telco Residential",
        "IsActive": true,
        "vlocity_cmt__RecurringPrice__c": 200,
        "Product2": {
          "attributes": {
            "type": "Product2",
            "url": "/services/data/v46.0/sobjects/Product2/01t4P000007VDOkQAO"
          },
          "Id": "01t4P000007VDOkQAO",
          "Name": "Telco Residential",
          "vlocity_cmt__IsConfigurable__c": false,
          "vlocity_cmt__Type__c": "None",
          "vlocity_cmt__SubType__c": "None",
          "vlocity_cmt__SellingStartDate__c": "2019-05-01T18:00:00.000+0000",
          "vlocity_cmt__SellingEndDate__c": "2019-09-30T18:00:00.000+0000",
          "vlocity_cmt__JSONAttribute__c": null
        },
        "CurrencyCode": "USD",
        "productId": "01t4P000007VDOkQAO",
        "defaultQuantity": 1,
        "minQuantity": 0,
        "maxQuantity": 99999,
        "groupMinQuantity": 0,
        "groupMaxQuantity": 99999,
        "sequenceNumber": 1,
        "productChildItemDefinition": {
          "attributes": {
            "type": "vlocity_cmt__ProductChildItem__c"
          },
          "Name": "Root PCI",
          "vlocity_cmt__IsVirtualItem__c": false,
          "vlocity_cmt__Quantity__c": 1,
          "vlocity_cmt__MaxQuantity__c": 99999,
          "vlocity_cmt__MinQuantity__c": 0,
          "vlocity_cmt__MaximumChildItemQuantity__c": 99999,
          "vlocity_cmt__MinimumChildItemQuantity__c": 0,
          "vlocity_cmt__IsOverride__c": false,
          "vlocity_cmt__ParentProductId__c": "01t4P000007VDOkQAO",
          "vlocity_cmt__ChildLineNumber__c": "1",
          "vlocity_cmt__SeqNumber__c": 1,
          "vlocity_cmt__CollapseHierarchy__c": false,
          "vlocity_cmt__IsRootProductChildItem__c": true,
          "vlocity_cmt__ParentProductId__r": {
            "attributes": {
              "type": "Product2",
              "url": "/services/data/v46.0/sobjects/Product2/01t4P000007VDOkQAO"
            },
            "Id": "01t4P000007VDOkQAO",
            "Name": "Telco Residential",
            "vlocity_cmt__SellingStartDate__c": "2019-05-01T18:00:00.000+0000",
            "vlocity_cmt__SellingEndDate__c": "2019-09-30T18:00:00.000+0000"
          }
        },
        "productHierarchyPath": "01t4P000007VDOkQAO",
        "name": "Telco Residential",
        "isVirtualItem": false,
        "lineNumber": "0001",
        "action": "Add",
        "hasChildren": true,
        "SellingPeriod": "Present",
        "itemType": "lineItem",
        "PricebookEntryId": {
          "value": "01u4P00000s2eZjQAI",
          "previousValue": null,
          "originalValue": null,
          "messages": [],
          "label": "Price Book Entry ID",
          "hidden": false,
          "fieldName": "PricebookEntryId",
          "editable": false,
          "dataType": "REFERENCE",
          "alternateValues": null,
          "actions": {}
        },
        "Quantity": {
          "value": 1,
          "previousValue": null,
          "originalValue": null,
          "messages": [],
          "label": "Quantity",
          "hidden": false,
          "fieldName": "Quantity",
          "editable": true,
          "dataType": "DOUBLE",
          "alternateValues": null,
          "actions": {}
        },
        "vlocity_cmt__OneTimeTotal__c": {
          "value": 400,
          "previousValue": null,
          "originalValue": null,
          "messages": [],
          "label": "One Time Total",
          "hidden": false,
          "fieldName": "vlocity_cmt__OneTimeTotal__c",
          "editable": false,
          "dataType": "CURRENCY",
          "alternateValues": null,
          "actions": {
            "adjustmentcodes": {
              "rest": {
                "params": {},
                "method": "GET",
                "link": "/services/apexrest/vlocity_cmt/v2/listsofvalues?listkeys=AdjustmentCodes&cartId=8014P0000022G0jQAE&id=8024P000001gdBNQAY&fields=vlocity_cmt__OneTimeTotal__c&PricingVariableCode=OT_STD_PRC_TOTAL"
              },
              "remote": {
                "params": {}
              },
              "client": {
                "records": [],
                "params": {}
              }
            },
            "pricedetail": {
              "rest": {
                "params": {},
                "method": "GET",
                "link": "/services/apexrest/vlocity_cmt/v2/cpq/carts/8014P0000022G0jQAE/items/8024P000001gdBNQAY/pricing?cartId=8014P0000022G0jQAE&id=8024P000001gdBNQAY&fields=vlocity_cmt__OneTimeTotal__c"
              },
              "remote": {
                "params": {}
              },
              "client": {
                "records": [],
                "params": {}
              }
            }
          }

        ...

        }
      }
    ]
  },
  "createCartAction": {
    "rest": {
      "params": {
        "cartContextKey": "20933d86217050b8d3b15654aeceae30"
      },
      "link": "/v3/carts",
      "method": "createCartAction"
    }
  },
  "errorCode": "INVOKE-200",
  "error": "OK"
}
```
