Update
1 min
The following is an example of updating the Estimate where we are changing some of the fields. (See Estimate for all available fields). The NetSuite estimate Id (internalId) is required to update the estimate.
Note: You can only update one record at a time.
The response returns the complete estimate information, but we have shortened the response in our example for ease of reading.
// Create a Map to store all the data of an Estimate
Map<String, Object> nsEstimate = new Map<String, Object>();
nsEstimate.put('internalId', '38310');
nsEstimate.put('entityStatus', new Map<String, Object>{'internalId'=>'11'});
nsEstimate.put('expectedCloseDate', DateTime.newInstance(2020, 10, 31).getTime()/1000);
// Initializing the Estimate Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItem = new Map<String, Object>();
lineItem.put('line', 1); // updates the existing line item with line number as 1.
lineItem.put('quantity', 2);
lineItemList.add(lineItem);
// Adding Another Line Item
lineItem = new Map<String, Object>();
lineItem.put('item', new Map<String, Object>{'internalId'=>'444'});
lineItem.put('quantity', 4);
lineItem.put('price', new Map<String, Object>{'internalId'=>'2'});
lineItemList.add(lineItem);
// Adding the Line Items to Estimate
Map<String, Object> estimateLineitemList = new Map<String, Object>();
estimateLineitemList.put('item', lineItemList);
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.
nsEstimate.put('itemList', estimateLineitemList);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('estimates', new List<Object>{nsEstimate});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'updateEstimate');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);