Global API
Code Examples

Invoice Flow

13min



Custom Apex Generator

This is an example Invocable Method generated by Breadwinner Apex Generator, which can be invoked by a standard Flow. This is quite useful as it shows how you can use Salesforce standard automation practices to drive QuickBooks record creation. Using this format you can extend to Update or Read in a similar fashion.

This basic use case shows how easy it is to create robust automation in Salesforce to facilitate Invoice record creation in QuickBooks. Extending upon this, using the Global API requests in this help site you can perform many automated retrieves, create, or update functions directly rather than requiring extensive middleware or endpoint processing to perform.



Apex Class Generation

Navigate to Breadwinner Setup > Tools > Apex Generator

Step 1: Choose the record mode Create/Edit on a QuickBooks object (Invoice) using a Flow and click on Next button.

Step 2: Select the option to Run this Flow as (I will check "Run Asynchronously" (on Record-Triggered flow creation Page))

Document image


Step 3: Click on Next, it will navigate to the Fields selection page. Click on Generate Apex.

Document image


Step 4: Copy the generated Apex Class / Apex Test Class (optional). Save/Deploy the copied code to the respective org.

Document image


QuickBooks Invoice Automation using Flows

Step 1: Navigate to Salesforce Setup > Flows > New Flow > Record-Triggered Flow and click on Create button.

Document image


Step 2: Choose the options similar to those mentioned below, and click on Done.

  1. Select the Object (Opportunity)
  2. Trigger Event (record is updated)
  3. Entry Conditions (like All Conditions Are Met (AND) > StageName equals Closed Won)
  4. Run the Flow for updated records (Only when the record is updated to meet the condition requirements)
  5. Optimize Flow for (Actions and Related Records)
  6. Check the Run Asynchronously path (Only when the option "I will check "Run Asynchronously" (on Record-Triggered flow creation Page)" on Step 2)
Document image


Step 3: Get Line Items (Opportunity Products query with Current Record ID (opportunity Id)), and click on Done.

  1. Select Get Records (from the Data section (Free-Form Layout))
  2. Give a Label as "Get Opportunity Products"
  3. Select Object for Line Records (Opportunity Product)
  4. Condition for Query (like All Conditions Are Met (AND) > (OpportunityId Equals $Record > Opportunity ID))
  5. Sorting (Ascending by #SortOrder)
  6. How Many Records to Store (All Records)
  7. How to Store (Automatically store all fields)
Document image


Step 4: Get QuickBooks Company Info (Customer Ref) using the Get Records data action, and click on Done. This is done to retrieve QuickBooks Customer Reference Id and other field values that are to pass to the QuickBooks Invoice.

How to ensure that we have the QuickBooks Customer record and its Reference value:

  • Complete the Account Match i.e associate the Salesforce Account to the QuickBooks Company (Customer) record
  • We have a Reference Id field on the QuickBooks Company that comes appended with the QuickBooks Org Id i.e "123145960748374-4", so we can either create a custom text (to pass the value manually) or a formula field (Customer ref) with return type as Text on the QuickBooks Company Object to retrieve the Id "4" value (Screenshot for Formula field).
Document image


Follow the Flow Steps

  1. Select Get Records (from the Data section (Free-Form Layout))
  2. Give a Label as "Get QuickBooks Company Info"
  3. Select Object for Info (QuickBooks Company)
  4. Condition for Query (like All Conditions Are Met (AND) > (breadwinner_qbo__Salesforce_Account__c Equals $Record > Account ID > Account ID))
  5. Sorting (Optional)
  6. How Many Records to Store (Only first record)
  7. How to Store (Automatically store all fields)
Document image


Step 5: Create an Apex Action using the "Create QuickBooks Invoice" Invocable method and Label it "Create QuickBooks Invoice"

Document image


Step 6: Map the Fields to Create Invoice in "Apex Action"

Before you start this step, please refer to the Invoice fields and their data types while mapping the values i.e. Lookup/Value Name records will need reference ids.

Also, prepare the required fields to use in the field mapping for the line items i.e to pass the QuickBook Items to the Flow properly so they populate as line items in QuickBooks.

  1. Line Item Detail Type is a required field. Please create a formula or text field on the chosen line records object (Opportunity Product) to pass the value "SalesItemLineDetail".
  2. QuickBooks Item Reference Id
    1. Complete the Product Match i.e, Navigate to Breadwinner Tab > Product match under Setup and Config section.
    2. Please create a formula field (return type - Text) or text field on the chosen line records object (Opportunity Product) to fetch the QuickBooks Item Reference Id.
    3. You will find the QuickBooks Item Reference Id on the QuickBooks Items Record view -> Additional Information -> Reference Id (note it comes with QuickBooks Org Id appended, so please use the second part of it). Ex: If Reference Id shows "123145960748374-47" then 47 is the value that we need to pass to QuickBooks.
    4. We can go with a formula field if the Product Match is done and fetch the value.
    5. For other than Opportunity Product, if there is a relation with the Salesforce Product, go with the formula field, else create a custom field to store the QuickBooks Item Reference Id.
Document image

Document image


Follow the Flow Steps:

  1. Select Object for "Invoice Line Items" input (Opportunity Product)
  2. Map the QuickBooks Company (Created from Step 4, Eg: {!Get_QuickBooks_Company_Info.Customer_Ref__c})
  3. Map the Line Records to "Invoice Line Items" (Created from Step 3, Eg: {!GetOpportunityProducts})
  4. Map the Line Record fields with Salesforce API Names (Field Name, Eg: Description) by coping as mentioned in the below image (Line API Names). Use the fields that we created to map the Line Item Detail Type and Item Ref.
Document image

Document image

Document image

Document image

Document image


Step 7: Connect the Flow Steps, click Save, and Activate

  1. Connect Record Trigger Flow Section to Get Opportunity Products (Run Asynchronously)
  2. Connect Get Opportunity Products to Get QuickBooks Company Info
  3. Connect Get QuickBooks Company Info to Create QuickBooks Invoice
Document image


Triggering QuickBooks Invoice creation

Step 1: Select the Opportunity

Document image


Step 2: Edit the Opportunity to meet Trigger Criteria (StageName equals Closed Won)

Document image


Step 3: Evaluate the created Invoice at QuickBooks

Document image