1// Create a Map to store all the data of an Estimate
2Map<String, Object> nsEstimate = new Map<String, Object>();
3 nsEstimate.put('classification', new Map<String, Object>{'internalId'=>'5'});
4 nsEstimate.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
5 nsEstimate.put('customForm', new Map<String, Object>{'internalId'=>'124'});
6 nsEstimate.put('department', new Map<String, Object>{'internalId'=>'2'});
7 nsEstimate.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
8 nsEstimate.put('discountRate', '-15');
9 nsEstimate.put('dueDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
10 nsEstimate.put('entity', new Map<String, Object>{'internalId'=>'362'});
11 nsEstimate.put('entityStatus', new Map<String, Object>{'internalId'=>'8'});
12 nsEstimate.put('expectedCloseDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
13 nsEstimate.put('externalId', 'SFId: a012w00000Oyssh');
14 nsEstimate.put('memo', 'Order 25');
15 nsEstimate.put('otherRefNum', '4343399');
16 nsEstimate.put('probability', 35);
17 nsEstimate.put('title', 'SF Estimate');
18 nsEstimate.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
19// Initializing the Estimate Custom Fields
20 List<Object> estCustomFieldList = new List<Object>();
21 Map<String, Object> estCustomField = new Map<String, Object>();
22 estCustomField.put('fieldType', 'select');
23 estCustomField.put('scriptId', 'custbody_customlist');
24 estCustomField.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
25 estCustomFieldList.add(estCustomField);
26
27// Adding the Estimate Custom Fields
28 nsEstimate.put('customFieldList', new Map<String, Object>{'customField'=>estCustomFieldList});
29
30 // Initializing the Estimate Line Items
31 List<Object> lineItemList = new List<Object>();
32 Map<String, Object> lineItem = new Map<String, Object>();
33 lineItem.put('description', 'A weapon for shooting arrows');
34 lineItem.put('item', new Map<String, Object>{'internalId'=>'239'});
35 lineItem.put('quantity', 1);
36 lineItem.put('rate', '999');
37
38 // Initializing the Line Item custom fields
39 List<Object> liCustomFieldList = new List<Object>();
40 Map<String, Object> liCustomField = new Map<String, Object>();
41 liCustomField.put('fieldType', 'boolean');
42 liCustomField.put('scriptId', 'custcol_checkbox');
43 liCustomField.put('value', 'true');
44 liCustomFieldList.add(liCustomField);
45
46// Adding the Estimate Line Item Custom Fields
47 lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
48 lineItemList.add(lineItem);
49
50// Adding the Line Items to Estimate
51 Map<String, Object> estimateLineitemList = new Map<String, Object>();
52 estimateLineitemList.put('item', lineItemList);
53 nsEstimate.put('itemList', estimateLineitemList);
54
55// Initializing the RequestJSON Data to be passed.
56Map<String, Object> requestJSONMap = new Map<String, Object>();
57 requestJSONMap.put('estimates', new List<Object>{nsEstimate});
58 String reqJSON = JSON.serialize(requestJSONMap);
59
60Map<String, Object> reqObj = new Map<String, Object>();
61 reqObj.put('version', '1.0');
62 reqObj.put('action', 'createEstimate');
63 reqObj.put('requestJSON', reqJSON);
64
65// Placing a request to Breadwinner Global API
66Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
67System.debug(resp);