1//Create a Map to store all the data of a Invoice
2Map<String, Object> nsInvoice = new Map<String, Object>();
3 nsInvoice.put('classification', new Map<String, Object>{'internalId'=>'5'});
4 nsInvoice.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
5 nsInvoice.put('department', new Map<String, Object>{'internalId'=>'2'});
6 nsInvoice.put('entity', new Map<String, Object>{'internalId'=>'362'});
7 nsInvoice.put('location',new Map<String, Object>{'internalId'=>'1'});
8 nsInvoice.put('memo', 'Invoice 100');
9 nsInvoice.put('otherRefNum', '4343399');
10 nsInvoice.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
11// Initializing the Invoice Custom Fields
12 List<Object> invCustomFieldList = new List<Object>();
13 Map<String,Object> invCustomField = new Map<String,Object>();
14 invCustomField.put('fieldType', 'select');
15 invCustomField.put('scriptId', 'custbody_customlist');
16 invCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
17 invCustomFieldList.add(invCustomField);
18
19// Adding the Invoice Custom Fields
20 nsInvoice.put('customFieldList', new Map<String,Object>{'customField'=>invCustomFieldList});
21
22 // Initializing the Invoice Line Items
23 List<Object> lineItemList = new List<Object>();
24 Map<String, Object> lineItem = new Map<String, Object>();
25 lineItem.put('description', 'A weapon for shooting arrows');
26 lineItem.put('item', new Map<String, Object>{'internalId'=>'239'});
27 lineItem.put('quantity', 3);
28// Initializing the Line Item custom fields
29 List<Object> liCustomFieldList = new List<Object>();
30 Map<String, Object> liCustomField = new Map<String, Object>();
31 liCustomField.put('fieldType', 'boolean');
32 liCustomField.put('scriptId', 'custcol_checkbox');
33 liCustomField.put('value', 'true');
34 liCustomFieldList.add(liCustomField);
35
36// Adding the Invoice Line Item Custom Fields
37 lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
38 lineItemList.add(lineItem);
39
40// Adding the Line Items to Invoice
41 Map<String, Object> invLineitemList = new Map<String, Object>();
42 invLineitemList.put('item', lineItemList);
43 nsInvoice.put('itemList', invLineitemList);
44
45// Initializing the RequestJSON Data to be passed.
46Map<String, Object> requestJSONMap = new Map<String, Object>();
47 requestJSONMap.put('invoices', new List<Object>{nsInvoice});
48 String reqJSON = JSON.serialize(requestJSONMap);
49
50Map<String, Object> reqObj = new Map<String, Object>();
51 reqObj.put('version', '1.0');
52 reqObj.put('action', 'createInvoice');
53 reqObj.put('requestJSON', reqJSON);
54
55// Placing a request to Breadwinner Global API
56Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
57System.debug(resp);
58
59
60