---
title: Create
slug: netsuite/fk9b-create
description: Learn how to create Credit Memo in NetSuite using the "createCreditMemo" action with code snippets in Apex language. Get the Credit Memo ID and Salesforce ID in the response for easy tracking and management.
docTags: 
createdAt: 2023-04-25T05:36:56.000Z
---

To create a Credit Memo in NetSuite, use action as "createCreditMemo" and pass the Credit Memo data in the requestJSON under "CreditMemos".

:::hint{type="info"}
Note: You can only create one record at a time.
:::

The following is an example of creating a Credit Memo where we are setting every possible field (See [Credit Memo](docId\:rOGVPWAviJlOdMLuJjwd5) for the available fields). The response will return the response back from NetSuite, which includes Credit Memo Id (internalId), plus the newly created Salesforce ﻿Credit Memo Id (salesforceID)

:::CodeblockTabs
Request

```apex
//  Create a Map to store all the data of a CM
Map<String, Object> nsCM = new Map<String, Object>();
    nsCM.put('classification', new Map<String, Object>{'internalId'=>'1'});
    nsCM.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
    nsCM.put('department', new Map<String, Object>{'internalId'=>'1'});
	nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
    nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
    nsCM.put('discountRate', '-15');
    nsCM.put('entity', new Map<String, Object>{'internalId'=>'109118'});
    nsCM.put('memo', 'Order 250');
    nsCM.put('otherRefNum', '4343399');
    nsCM.put('tranDate', DateTime.newInstance(2023, 04, 26).getTime()/1000);
//  Initializing the CM Custom Fields
    List<Object> cmCustomFieldList = new List<Object>();
    Map<String, Object> cmCustomField = new Map<String, Object>();
        cmCustomField.put('fieldType', 'select');
        cmCustomField.put('scriptId', 'custbody_customlist');
        cmCustomField.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
        cmCustomFieldList.add(cmCustomField);

//  Adding the CM Custom Fields
    nsCM.put('customFieldList', new Map<String, Object>{'customField'=>cmCustomFieldList});

//  Initializing the CM Line Items
    List<Object> lineItemList = new List<Object>();
    Map<String, Object> lineItem = new Map<String, Object>();
        lineItem.put('description', 'A weapon for shooting arrows');
        lineItem.put('item', new Map<String, Object>{'internalId'=>'9524'});
        lineItem.put('quantity', 1);
		lineItem.put('Amount', 1000);

//  Initializing the Line Item custom fields
        List<Object> liCustomFieldList = new List<Object>();
        Map<String, Object> liCustomField = new Map<String, Object>();
            liCustomField.put('fieldType', 'boolean');
            liCustomField.put('scriptId', 'custcol_checkbox');
            liCustomField.put('value', 'true');
            liCustomFieldList.add(liCustomField);

//  Adding the CM Line Item Custom Fields
        lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
        lineItemList.add(lineItem);

//  Adding the Line Items to CM
    Map<String, Object> cmLineitemList = new Map<String, Object>();
        cmLineitemList.put('item', lineItemList);
    nsCM.put('itemList', cmLineitemList);

//  Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
    requestJSONMap.put('CreditMemos', new List<Object>{nsCM});
    String reqJSON = JSON.serialize(requestJSONMap);

Map<String, Object> reqObj = new Map<String, Object>();
    reqObj.put('version', '1.0');
    reqObj.put('action', 'createCreditMemo');
    reqObj.put('requestJSON', reqJSON);

//  Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
```

Response

```json
{
  action=createCreditMemo,
  timestamp = 1682505158494,
  validRequest = true,
  version = 1.0,
  responseJSON={
    "status": "200",
    "errors": [],
    "creditMemos": [
      {
        "tranId": "170",
        "tranDate": 1682478000,
        "total": 985.0,
        "taxTotal": 0.0,
        "subTotal": 1000.0,
        "subsidiary": {
          "type": null,
          "name": "Parent Company",
          "internalId": "1",
          "externalId": null
        },
        "status": "Open",
        "shippingCost": 0.0,
        "salesRep": null,
        "salesforceID": "a061e000003UzJyAAK",
        "refundCheck": null,
        "otherRefNum": "4343399",
        "memo": "Order 250",
        "location": {
          "type": null,
          "name": "Hyderabad : Hi-Tech City",
          "internalId": "10",
          "externalId": null
        },
        "lastModifiedDate": 1682505153,
        "job": null,
        "itemList": {
          "replaceAll": null,
          "item": [
            {
              "unitsDisplay": null,
              "taxRate1": "0.0",
              "taxCode": {
                "type": null,
                "name": "VAT_IN:UNDEF-IN",
                "internalId": "5",
                "externalId": null
              },
              "tax1Amt": 0.0,
              "shipMethod": null,
              "shipGroup": null,
              "serialNumbers": null,
              "revRecStartDate": null,
              "revRecSchedule": null,
              "revRecEndDate": null,
              "rate": null,
              "quantityRemaining": null,
              "quantityReceived": null,
              "quantityPicked": null,
              "quantityPacked": null,
              "quantityOnHand": null,
              "quantityFulfilled": null,
              "quantityCommitted": null,
              "quantityBilled": null,
              "quantityBackOrdered": null,
              "quantityAvailable": null,
              "quantity": 1.0,
              "price": {
                "type": null,
                "name": null,
                "internalId": "-1",
                "externalId": null
              },
              "poNum": null,
              "percentComplete": null,
              "orderLine": null,
              "onHand": null,
              "location": null,
              "line": 1,
              "jobName": null,
              "itemReceive": null,
              "itemName": null,
              "itemIsFulfilled": null,
              "item": {
                "type": null,
                "name": "Electronic Oven",
                "internalId": "9524",
                "externalId": null
              },
              "isClosed": null,
              "grossAmt": 1000.0,
              "expectedReceiptDate": null,
              "description": "A weapon for shooting arrows",
              "department": null,
              "customFieldList": {
                "customField": [
                  {
                    "valueLookup": null,
                    "value": "true",
                    "scriptId": "custcol_checkbox",
                    "internalId": "443",
                    "fieldType": null
                  }
                ]
              },
              "createPo": null,
              "costEstimateType": "_itemDefinedCost",
              "costEstimate": 0.0,
              "classification": null,
              "billingSchedule": null,
              "amount": 1000.0
            }
          ]
        },
        "internalId": "121563",
        "handlingCost": 0.0,
        "externalId": null,
        "exchangeRate": 1.0,
        "entity": {
          "type": null,
          "name": "CUST1402AT Blue Origin",
          "internalId": "109118",
          "externalId": null
        },
        "discountTotal": -15.0,
        "discountRate": "-15.00",
        "discountItem": {
          "type": null,
          "name": "Partner Discount",
          "internalId": "-6",
          "externalId": null
        },
        "department": {
          "type": null,
          "name": "PR Department",
          "internalId": "1",
          "externalId": null
        },
        "customForm": {
          "type": null,
          "name": "Custom Credit Memo 2",
          "internalId": "114",
          "externalId": null
        },
        "customFieldList": {
          "customField": [
            {
              "valueLookup": null,
              "value": "985",
              "scriptId": "custbody42",
              "internalId": "869",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": " - ",
              "scriptId": "custbody_breadwinner_pc_internal_id",
              "internalId": "588",
              "fieldType": null
            },
            {
              "valueLookup": {
                "type": null,
                "name": "B",
                "internalId": "2",
                "externalId": null
              },
              "value": null,
              "scriptId": "custbody_customlist",
              "internalId": "458",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody_checkbox",
              "internalId": "272",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "2",
              "scriptId": "custbody15",
              "internalId": "182",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody_enableimport",
              "internalId": "691",
              "fieldType": null
            }
          ]
        },
        "currencyRecord": {
          "type": null,
          "name": "INR",
          "internalId": "1",
          "externalId": null
        },
        "currencyName": "INR",
        "createdFrom": null,
        "createdDate": 1682505153,
        "classification": {
          "type": null,
          "name": "Partner Class",
          "internalId": "1",
          "externalId": null
        },
        "applyList": null,
        "applied": 0.0,
        "account": {
          "type": null,
          "name": "Accounts Receivable",
          "internalId": "122",
          "externalId": null
        }
      }
    ]
  }
}
```
:::

