---
title: Create
slug: netsuite/qtT9-create
description: Learn how to create a Sales Order in NetSuite with ease using the "createSalesOrder" action and passing relevant data in the requestJSON. This comprehensive guide provides step-by-step instructions for setting fields like classification, currency, departm
docTags: 
createdAt: 2021-10-26T11:39:15.000Z
---

To create a Sales Order in NetSuite, use action as "createSalesOrder" and pass the Sales Order data in the requestJSON under "salesOrders".

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

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

:::CodeblockTabs
Request

```apex
// Create a Map to store all the data of a Sales Order
Map<String, Object> nsSalesOrder = new Map<String, Object>();
nsSalesOrder.put('classification', new Map<String, Object>{'internalId'=>'5'});
nsSalesOrder.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
nsSalesOrder.put('department', new Map<String, Object>{'internalId'=>'2'});
nsSalesOrder.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
nsSalesOrder.put('discountRate', '-15');
nsSalesOrder.put('entity', new Map<String, Object>{'internalId'=>'362'});
nsSalesOrder.put('memo', 'Order 25');
nsSalesOrder.put('otherRefNum', '4343399');
nsSalesOrder.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);

// Initialize the Sales Order Custom Fields
List<Object> soCustomFieldList = new List<Object>();
Map<String,Object> soCustomField = new Map<String,Object>();
soCustomField.put('fieldType', 'select');
soCustomField.put('scriptId', 'custbody_customlist');
soCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
soCustomFieldList.add(soCustomField);

// Add custom segment field
Map<String,Object> soCustomField2 = new Map<String,Object>();
soCustomField2.put('fieldType', 'select');
soCustomField2.put('scriptId', 'cseg_lead_source');
soCustomField2.put('valueLookup', new Map<String,Object>{'internalId'=>'3'});
soCustomFieldList.add(soCustomField2);

// Add the Sales Order Custom Fields
nsSalesOrder.put('customFieldList', new Map<String,Object>{'customField'=>soCustomFieldList});

// Initializing the Sales Order 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'=>'239'});
lineItem.put('quantity', 1);
lineItem.put('price',new Map<String, Object>{'internalId'=>'-1'});
lineItem.put('rate', '999');

// Initialize 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);

// Add custom segment field
Map<String,Object> liCustomField2 = new Map<String,Object>();
liCustomField2.put('fieldType', 'select');
liCustomField2.put('scriptId', 'cseg_lead_source');
liCustomField2.put('valueLookup', new Map<String,Object>{'internalId'=>'3'});
liCustomFieldList.add(liCustomField2);

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

// Add the Line Items to Sales Order
Map<String, Object> soLineitemList = new Map<String, Object>();
soLineitemList.put('item', lineItemList);

nsSalesOrder.put('itemList', soLineitemList);

//  Initialize the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('salesOrders', new List<Object>{nsSalesOrder});

String reqJSON = JSON.serialize(requestJSONMap);

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

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

Response

```json
{
  action=createSalesOrder,
  timestamp=1606471494020,
  validRequest=true,
  version=1.0,
  responseJSON={
    "status": "200",
    "errors": [],
    "salesOrders": [
      {
        "tranId": "12320000000000117",
        "tranDate": 1599417000,
        "total": 984.0,
        "taxTotal": 0.0,
        "subTotal": 999.0,
        "subsidiary": {
          "type": null,
          "name": "Parent Company",
          "internalId": "1",
          "externalId": null
        },
        "status": "Pending Approval",
        "shippingCost": null,
        "salesRep": null,
        "salesforceID": "a0D2w0000092RCKEA2",
        "otherRefNum": "4343399",
        "nullFieldList": null,
        "memo": "Order 25",
        "location": null,
        "lastModifiedDate": 1606471491,
        "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": "999.00",
              "quantityRemaining": null,
              "quantityReceived": null,
              "quantityBilled": 0.0,
              "quantity": 1.0,
              "price": {
                "type": null,
                "name": null,
                "internalId": "-1",
                "externalId": null
              },
              "poNum": null,
              "orderLine": null,
              "onHand": null,
              "location": null,
              "line": 1,
              "jobName": null,
              "itemReceive": null,
              "itemName": null,
              "itemIsFulfilled": null,
              "item": {
                "type": null,
                "name": "Bow",
                "internalId": "239",
                "externalId": null
              },
              "grossAmt": 999.0,
              "expectedReceiptDate": null,
              "description": "A weapon for shooting arrows",
              "department": null,
              "customFieldList": {
                "customField": [
                  {
                    "valueLookup": null,
                    "value": "1",
                    "scriptId": "custcol_gh_line_no",
                    "internalId": "175",
                    "fieldType": null
                  },
                  {
                    "valueLookup": null,
                    "value": "12320000000000117_72960",
                    "scriptId": "custcol_gh_so_line_id",
                    "internalId": "200",
                    "fieldType": null
                  },
                  {
                    "valueLookup": {
                      "type": null,
                      "name": "Web",
                      "internalId": "3",
                      "externalId": null
                    },
                    "value": null,
                    "scriptId": "cseg_lead_source",
                    "internalId": "559",
                    "fieldType": null
                  },
                  {
                    "valueLookup": null,
                    "value": "false",
                    "scriptId": "custcol_checkbox",
                    "internalId": "443",
                    "fieldType": null
                  }
                ]
              },
              "createPo": "_dropShipment",
              "costEstimateType": null,
              "costEstimate": null,
              "classification": null,
              "amount": 999.0
            }
          ]
        },
        "internalId": "54352",
        "handlingCost": null,
        "externalId": null,
        "exchangeRate": 1.0,
        "entity": {
          "type": null,
          "name": "21 Atherton Grocery",
          "internalId": "362",
          "externalId": null
        },
        "discountTotal": -15.0,
        "discountRate": "-15.00",
        "discountItem": {
          "type": null,
          "name": "Partner Discount",
          "internalId": "-6",
          "externalId": null
        },
        "department": {
          "type": null,
          "name": "Sales",
          "internalId": "2",
          "externalId": null
        },
        "customForm": {
          "type": null,
          "name": "Custom Sales Order 2",
          "internalId": "121",
          "externalId": null
        },
        "customFieldList": {
          "customField": [
            {
              "valueLookup": {
                "type": null,
                "name": "B",
                "internalId": "2",
                "externalId": null
              },
              "value": null,
              "scriptId": "custbody_customlist",
              "internalId": "458",
              "fieldType": null
            },
            {
              "valueLookup": {
                "type": null,
                "name": "Web",
                "internalId": "3",
                "externalId": null
              },
              "value": null,
              "scriptId": "cseg_lead_source",
              "internalId": "559",
              "fieldType": null
            },
            {
              "valueLookup": null,
              "value": "false",
              "scriptId": "custbody_checkbox",
              "internalId": "272",
              "fieldType": null
            }
          ]
        },
        "currencyRecord": null,
        "currencyName": "US Dollars",
        "createdFrom": null,
        "createdDate": 1606471488,
        "classification": {
          "type": null,
          "name": "Corporate Sales",
          "internalId": "5",
          "externalId": null
        }
      }
    ]
  }
}
```
:::

### Pass Billing and Shipping Addresses

When passing an existing NetSuite Customer address as the billing/shipping address for a Sales Order, refer to the sample code below.

:::CodeblockTabs
Request

```apex
// Add the Customer's existing address as Sales Order's billing address
nsSalesOrder.put('billAddressList', new Map<String, Object>{'internalId'=>'7825'});

// Add the Customer's existing address as Sales Order's shipping address
nsSalesOrder.put('shipAddressList', new Map<String, Object>{'internalId'=>'7826'});
```
:::

When passing a custom billing/shipping address specific to Sales Orders only, you can refer to the sample code provided below.

:::CodeblockTabs
Request

```apex
// Initialize the Sales Order's custom Billing Address
Map<String, Object> billingAddressDetails = new Map<String, Object>();
billingAddressDetails.put('attention','Plum A');
billingAddressDetails.put('addressee','Plum ABC');
billingAddressDetails.put('addr1','2334 N. Michigan Avenue, Suite 1500');
billingAddressDetails.put('addr2','Near ABC block');
billingAddressDetails.put('city','Chicago');
billingAddressDetails.put('state','IL');
billingAddressDetails.put('country','_unitedStates');
billingAddressDetails.put('zip','60601');

// Add the Sales Order's custom Billing Address
nsSalesOrder.put('billingAddress', billingAddressDetails);

// Initialize the Sales Order's custom Shipping Address
Map<String, Object> shippingAddressDetails = new Map<String, Object>();
shippingAddressDetails.put('attention','Plum X');
shippingAddressDetails.put('addressee','Plum XYZ');
shippingAddressDetails.put('addr1','525 S. Lexington Ave');
shippingAddressDetails.put('addr2','Near XYZ block');
shippingAddressDetails.put('city','Burlington');
shippingAddressDetails.put('state','NC');
shippingAddressDetails.put('country','_unitedStates');
shippingAddressDetails.put('zip','27215');

// Add the Sales Order's custom Shipping Address
nsSalesOrder.put('shippingAddress', shippingAddressDetails);

```
:::

