Create
1min
The following is an example of create Invoice where we are setting every possible field (See Invoice for the available fields). The response will return the exact request data plus the new QuickBooks Invoice Id (Id) and the newly created Salesforce Invoice Id (salesforceRecordId).
Request
Response
|
// Create a Map to store all the data of a Invoice List<Object> invoiceList = new List<Object>(); Map<String, Object> invoiceMap = new Map<String, Object>(); invoiceMap.put('TxnDate', '2021/08/11'); invoiceMap.put('DueDate', '2021/09/11'); invoiceMap.put('DocNumber', 'Inv-1201'); invoiceMap.put('ExchangeRate', 1.0); // Initializing the Invoice Custom Fields List<Object> customFieldList = new List<Object>(); Map<String, Object> customFiel1dMap = new Map<String, Object>(); customFiel1dMap.put('DefinitionId','1'); customFiel1dMap.put('Type','StringType'); customFiel1dMap.put('StringValue','Received'); customFieldList.add(customFiel1dMap); // Adding the Invoice Custom Fields invoiceMap.put('CustomField',customFieldList); invoiceMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'}); invoiceMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'}); invoiceMap.put('CustomerRef',new Map<String, Object>{'value' => '29'}); // Initializing the Billing Address Map<String, Object> billAddrMap = new Map<String, Object>(); billAddrMap.put('City' , 'Suryapet'); billAddrMap.put('Country' , 'India'); billAddrMap.put('Line3' , 'Kodad'); billAddrMap.put('Line2' , 'First Lane'); billAddrMap.put('Line1' , '1-24'); billAddrMap.put('PostalCode' , '508238'); billAddrMap.put('CountrySubDivisionCode' , ''); invoiceMap.put('BillAddr',billAddrMap); // Initializing the Invoice Line Items List<Object> lineItemList = new List<Object>(); Map<String, Object> lineItemMap = new Map<String, Object>(); lineItemMap.put('LineNum',1); lineItemMap.put('Amount',100); lineItemMap.put('Description','Description'); lineItemMap.put('DetailType', 'SalesItemLineDetail'); Map<String, Object> salesLineItemDetailMap = new Map<String, Object>(); salesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => '1'}); salesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'}); salesLineItemDetailMap.put('ClassRef' , new Map<String, Object>{'value' => '5000000000000193289'}); salesLineItemDetailMap.put('ServiceDate','1993/05/25'); //yyyy/MM/dd salesLineItemDetailMap.put('Qty',2); salesLineItemDetailMap.put('UnitPrice',50); salesLineItemDetailMap.put('TaxInclusiveAmt',22); lineItemMap.put('SalesItemLineDetail', salesLineItemDetailMap); lineItemList.add(lineItemMap); // Shipping charge is applied as a part of line items Map<String, Object> shippingLineItemMap = new Map<String, Object>(); shippingLineItemMap.put('Amount',10); shippingLineItemMap.put('DetailType', 'SalesItemLineDetail'); Map<String, Object> shippingSalesLineItemDetailMap = new Map<String, Object>(); shippingSalesLineItemDetailMap.put('ItemRef' , new Map<String, Object>{'value' => 'SHIPPING_ITEM_ID'}); shippingSalesLineItemDetailMap.put('TaxCodeRef' , new Map<String, Object>{'value' => 'TAX'}); shippingLineItemMap.put('SalesItemLineDetail', shippingSalesLineItemDetailMap); lineItemList.add(shippingLineItemMap); // Adding the Line Items to Invoice invoiceMap.put('Line',lineItemList); invoiceList.add(invoiceMap); // Initializing the RequestJSON Data to be passed. Map<String, Object> reqJSONMap = new Map<String, Object>(); reqJSONMap.put('invoices' , invoiceList); String reqJSON = JSON.serialize(reqJSONMap); Map<String, Object> finalReqMap = new Map<String, Object>(); Map<String, Object> reqOptions = new Map<String, Object>(); finalReqMap.put('options' , reqOptions); finalReqMap.put('version' , '1.0'); finalReqMap.put('action' , 'createinvoice'); finalReqMap.put('RequestJSON' , reqJSON); finalReqMap.put('skipDML' , false); //Required, if QuickBooks Multi-Org is enabled in Breadwinner. finalReqMap.put('qbOrgId', '!aa00TM'); System.debug('Request ::: ' + finalReqMap); // Placing a request to Breadwinner Global API Map<String, Object> respMap = breadwinner_qbo.BreadwinnerQBAPI.call(finalReqMap); System.debug('Response ::: ' + respMap);