1// Create a Map to store all the data of a Credit Memo
2List<Object> creditMemoList = new List<Object>();
3Map<String, Object> creditMemoMap = new Map<String, Object>();
4 creditMemoMap.put('Id', '13');
5 creditMemoMap.put('SyncToken','2');
6 creditMemoMap.put('CustomerRef',new Map<String, Object>{'value' => '9'});
7
8 // Initializing the Invoice Line Items
9 List<Object> lineItemList = new List<Object>();
10 Map<String, Object> lineItemMap = new Map<String, Object>();
11 lineItemMap.put('LineNum',1);
12 lineItemMap.put('Amount',100);
13 lineItemMap.put('Description','Description Updated');
14 lineItemMap.put('DetailType', 'SalesItemLineDetail');
15 Map<String, Object> salesLineItemDetailMap = new Map<String, Object>();
16 salesLineItemDetailMap.put('Qty',2);
17 salesLineItemDetailMap.put('UnitPrice',50);
18 salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'});
19
20 lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap);
21 lineItemList.add(lineItemMap);
22
23 // Adding the Line Items to Invoice
24 creditMemoMap.put('Line',lineItemList);
25 creditMemoList.add(creditMemoMap);
26
27// Initializing the RequestJSON Data to be passed.
28 Map<String, Object> reqJSONMap = new Map<String, Object>();
29 reqJSONMap.put('creditmemos' , creditMemoList);
30 String reqJSON = JSON.serialize(reqJSONMap);
31
32 Map<String, Object> finalReqMap = new Map<String, Object>();
33 Map<String, Object> reqOptions = new Map<String, Object>();
34 finalReqMap.put('options' , reqOptions);
35 finalReqMap.put('version' , '1.0');
36 finalReqMap.put('action' , 'updateCreditMemo');
37 finalReqMap.put('RequestJSON' , reqJSON);
38 finalReqMap.put('skipDML' , false);
39 //Required, if QuickBooks Multi-Org is enabled in Breadwinner.
40 finalReqMap.put('qbOrgId', '4620816365285051610');
41 System.debug('Request ::: ' + finalReqMap);
42
43// Placing a request to Breadwinner Global API
44 Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap);
45 System.debug('Response ::: ' + respMap);