1//Create a Map to store all the data of a Cash Sale
2Map<String, Object> nsCashSale = new Map<String, Object>();
3 nsCashSale.put('internalId', '91704');
4 nsCashSale.put('classification', new Map<String, Object>{'internalId'=>'2'});
5 nsCashSale.put('department', new Map<String, Object>{'internalId'=>'1'});
6 nsCashSale.put('memo', 'CashSale 215');
7 nsCashSale.put('otherRefNum', '43434544');
8// Initializing the Cash Sale Custom Fields
9 List<Object> csCustomFieldList = new List<Object>();
10 Map<String,Object> csCustomField = new Map<String,Object>();
11 csCustomField.put('fieldType', 'boolean');
12 csCustomField.put('scriptId', 'custbody_checkbox');
13 csCustomField.put('value', 'false');
14 csCustomFieldList.add(csCustomField);
15
16// Adding the Cash Sale Custom Fields
17 nsCashSale.put('customFieldList', new Map<String,Object>{'customField'=>csCustomFieldList});
18
19 // Initializing the Cash Sale Line Items
20 List<Object> lineItemList = new List<Object>();
21 Map<String, Object> lineItem = new Map<String, Object>();
22 lineItem.put('description', ' For shooting arrows');
23 lineItem.put('line', 1); // updates the existing line item with line number as 1.
24 lineItem.put('quantity', 15);
25// Initializing the Line Item custom fields
26 List<Object> liCustomFieldList = new List<Object>();
27 Map<String, Object> liCustomField = new Map<String, Object>();
28 liCustomField.put('fieldType', 'boolean');
29 liCustomField.put('scriptId', 'custcol_checkbox');
30 liCustomField.put('value', 'true');
31 liCustomFieldList.add(liCustomField);
32
33// Adding the Cash Sale Line Item Custom Fields
34 lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
35 lineItemList.add(lineItem);
36// Adding the Line Items to Cash Sale
37 Map<String, Object> csLineitemList = new Map<String, Object>();
38 csLineitemList.put('item', lineItemList);
39 csLineitemList.put('replaceAll', false);
40 nsCashSale.put('itemList', csLineitemList);
41
42// Initializing the RequestJSON Data to be passed.
43Map<String, Object> requestJSONMap = new Map<String, Object>();
44 requestJSONMap.put('cashSales', new List<Object>{nsCashSale});
45 String reqJSON = JSON.serialize(requestJSONMap);
46
47Map<String, Object> reqObj = new Map<String, Object>();
48 reqObj.put('version', '1.0');
49 reqObj.put('action', 'updateCashSale');
50 reqObj.put('requestJSON', reqJSON);
51
52// Placing a request to Breadwinner Global API
53Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
54System.debug(resp);