website logo
Product Overview
NetSuite
Payments
QuickBooks
Xero
Navigate through spaces
⌘K
Guided Wizard
Guided Wizard Settings
Bill Configuration
Custom Guided Wizard
Button URL Structure
Button URL Generator
Support
Global API
API Overview
Request
Response
Code Examples
Technical Resources
Breadwinner Setup
Requirements
ERD / Object Structure
Getting Help
Version History
Docs powered by archbee 

Create

1min

The following is an example of create a Credit Memo where we are setting every possible field (See Credit Memo for the available fields). The response will return the exact request data plus the new QuickBooks Credit Memo Id (Id) and the newly created Salesforce Credit Memo Id (salesforceRecordId)

Request
Response
|
//  Create a Map to store all the data of a Credit Memo
List<Object> creditMemoList = new List<Object>();
Map<String, Object> creditMemoMap = new Map<String, Object>();
    creditMemoMap.put('TxnDate', '2021/08/11');
    creditMemoMap.put('DocNumber', '1201');
    creditMemoMap.put('ExchangeRate', 1.0);

    //  Initializing the Credit Memo 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 Credit Memo Custom Fields
    creditMemoMap.put('CustomField',customFieldList);

    creditMemoMap.put('Address',new Map<String, Object>{'FreeFormNumber' => '+919090909090'});
    creditMemoMap.put('SalesTermRef',new Map<String, Object>{'value' => '4'});
    creditMemoMap.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' , '');
    creditMemoMap.put('BillAddr',billAddrMap);

    //  Initializing the Credit Memo 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);

    //  Adding the Line Items to Credit Memo
    creditMemoMap.put('Line',lineItemList);
    creditMemoList.add(creditMemoMap);

//  Initializing the RequestJSON Data to be passed.
    Map<String, Object> reqJSONMap = new Map<String, Object>(); 
    reqJSONMap.put('creditmemos' , creditMemoList); 
    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' , 'createCreditMemo'); 
    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);




Updated 02 Jun 2023
Did this page help you?
Yes
No
PREVIOUS
Read
NEXT
Update
Docs powered by archbee