1// Create a Map to store all the data of an Estimate
2Map<String, Object> nsEstimate = new Map<String, Object>();
3 nsEstimate.put('internalId', '38310');
4 nsEstimate.put('entityStatus', new Map<String, Object>{'internalId'=>'11'});
5 nsEstimate.put('expectedCloseDate', DateTime.newInstance(2020, 10, 31).getTime()/1000);
6
7 // Initializing the Estimate Line Items
8 List<Object> lineItemList = new List<Object>();
9 Map<String, Object> lineItem = new Map<String, Object>();
10 lineItem.put('line', 1); // updates the existing line item with line number as 1.
11 lineItem.put('quantity', 2);
12 lineItemList.add(lineItem);
13
14 // Adding Another Line Item
15 lineItem = new Map<String, Object>();
16 lineItem.put('item', new Map<String, Object>{'internalId'=>'444'});
17 lineItem.put('quantity', 4);
18 lineItem.put('price', new Map<String, Object>{'internalId'=>'2'});
19 lineItemList.add(lineItem);
20
21 // Adding the Line Items to Estimate
22 Map<String, Object> estimateLineitemList = new Map<String, Object>();
23 estimateLineitemList.put('item', lineItemList);
24 estimateLineitemList.put('replaceAll', false); // setting this as false, would create a new, or update, the line items passed in the Request based on the Line Number.
25
26 nsEstimate.put('itemList', estimateLineitemList);
27
28// Initializing the RequestJSON Data to be passed.
29Map<String, Object> requestJSONMap = new Map<String, Object>();
30 requestJSONMap.put('estimates', new List<Object>{nsEstimate});
31 String reqJSON = JSON.serialize(requestJSONMap);
32
33Map<String, Object> reqObj = new Map<String, Object>();
34 reqObj.put('version', '1.0');
35 reqObj.put('action', 'updateEstimate');
36 reqObj.put('requestJSON', reqJSON);
37
38// Placing a request to Breadwinner Global API
39Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
40System.debug(resp);