Technical Documentation - Customer Default Terms

1. Overview

QuickBooks lets each customer have a default payment term (for example Net 15), stored on the QuickBooks Customer as SalesTermRef. The connector now reads that term when customers are pulled into Salesforce. When a new invoice is sent to QuickBooks with no term of its own, it uses the customer's term and recalculates the Due Date from it. Invoices that already have a term are never changed.

2. What changed

Area

Change

Customer pull (QB → SF)

The customer's SalesTermRef (name and QuickBooks Id) is read from the QuickBooks response. A missing SalesTermRef means the customer has no default term.

Customer record

The term's QuickBooks Id is saved in Quickbooks_Term_QB_Id__c and the Term__c lookup is linked to the matching Quickbooks_Term__c record.

Invoice push (SF → QB)

New invoices with no term get the customer's term and a recalculated Due Date before the request is sent.

3. Objects and fields

Object

Field

Purpose

Quickbooks_Customer__c

Quickbooks_Term_QB_Id__c

QuickBooks Id of the customer's default term

Quickbooks_Customer__c

Term__c

Lookup to the matching Quickbooks_Term__c record

Quickbooks_Term__c

Name, QB_Id__c, Due_Days__c, Active__c, Quickbooks_Company__c, RealmId__c, Composite_Key__c

Term details, synced by BatchAllQBSFTermSync

4. How it works

4.1 Customer pull

  1. WS_Quickbooks reads SalesTermRef from the QuickBooks customer and keeps its name and value.

  2. WS_Quickbooks.createCustomerRecords saves the term's QuickBooks Id on the customer record.

  3. The Term__c lookup is first cleared, then linked only if a Quickbooks_Term__c exists with the same QB_Id__c for the same company.

  4. Terms are synced by BatchAllQBSFTermSync before customers, so the matching term records already exist when the customers are processed.

4.2 Invoice default term

CMQBConnectorUtility.applyCustomerDefaultTerm(invoices, companyRecordId) runs just before the invoice is sent to QuickBooks. It is called from:

  • BatchSFQBInvoiceSync

  • QueueableAutomateQBService

An invoice gets the customer's term only when all of these are true:

  • It is a new invoice (no QuickBooks Id, no SyncToken, or a locally built placeholder Id).

  • It has no term of its own (terms and salesTermRef are both blank).

  • It has a QuickBooks customer reference.

  • The customer record has a Quickbooks_Term_QB_Id__c for this company.

  • That term exists and is active (Active__c = true) for the company.

When it applies:

  • terms and salesTermRef (value and name) are set to the customer's term.

  • Due Date is recalculated as Invoice Date plus the term's Due_Days__c.

  • The date keeps its original format, either yyyy-MM-dd or the running user's locale format.

4.3 When nothing changes

  • The invoice has an explicit term.

  • The invoice already exists in QuickBooks.

  • The customer has no term, or the term is inactive or not found.

  • Any error inside the method is caught and written to the debug log. The invoice is then sent as before, without a default term.

5. Prerequisites

  • Run the term sync (BatchAllQBSFTermSync) before the customer sync, and again whenever terms change in QuickBooks.

  • Customers must be synced from QuickBooks so their term fields are populated.

6. Testing

CustomerDefaultTermTest covers:

  • Mapping SalesTermRef from the customer response.

  • Linking the Term__c lookup in createCustomerRecords.

  • The invoice fallback: ISO and locale date formats, inactive term, no term, explicit term, and existing invoice.

7. Troubleshooting

Symptom

Likely cause

New invoice has no term

The customer has no default term in QuickBooks, the term sync has not run, or the term is inactive.

Term__c lookup blank on the customer

The term sync ran after the customer sync. Run the terms and then the customers again.

Due Date unchanged

The term has no Due_Days__c, or the invoice has no Invoice Date.