Enabling Event-Based Invoice Creation
Your organization's business may require to create an invoice as soon as a business event occurs – an order is activated, a case is closed, a milestone is completed.
Summary
To this end, JustOn Billing & Invoice Management provides the invocable action Create Invoice from GIR (single source). You use this action to set up a flow that creates the invoice for the record that has triggered it, based on an existing generic invoice run configuration.
For details about the underlying behavior, see Event-Based Invoice Creation.
Setting up event-based invoice creation involves the following steps:
Note
Depending on your use cases, the flow setup and the objects to involve will vary.
Preparing Source Object
The action reuses the generic invoice run configuration. If your source object is already set up for the generic invoice run, there is nothing left to prepare.
Otherwise, set it up as described in Billing Arbitrary Objects, which includes:
-
Adding the required
ONfields to the source object – either as a parent-child or a single object configuration.Two of these fields have a specific relevance for the event-based creation:
API Name Relevance ON_Invoice Receives the ID of the produced invoice. In addition, it is the field that the duplicate protection evaluates before creating another invoice. ON_InvoiceBuildError Receives the error text if the invoice build fails after the action has finished – that is, during the asynchronous processing. -
Creating an invoice run filter for the source object.
Filter Field Value Name A unique name, like, for example, OrderActivationInvoice
You only need it in the flow to disambiguate if the source object has more than one generic filter.Use Case GenericTarget The API name of the source object, like, for example, OrderorMyOrder__c
Must match the records that you pass to the action.Child Relation The child relationship name if the invoice line items originate from child records
Leave empty if the source record itself holds the line item data (ON_IsItem=true, "is item" configuration).Transactional Suffix The control field suffix, if used
If set toOrder, for example, the mapping reads the fieldsON_...Order__cinstead ofON_...__c.
Info
JustOn recommends using a dedicated transactional suffix for the event-based filter if the same object is invoiced by a scheduled generic invoice run as well. This keeps the two configurations separate from each other and preserves the ON_LastInvoiceRun audit information of the scheduled run.
Note
The created filter is an ordinary generic filter. It is therefore also available on the invoice run page and via the Invoice Build button.
In addition, make sure that the users who trigger the flow have read access to the source records as well as create and edit access to invoices and invoice line items. The action runs in the context of the calling user.
Setting Up Flow
- Click to enter Setup, then navigate to Process Automation > Flows.
- Click New Flow.
-
Select the flow type as required, then click Create.
The action works in screen, autolaunched, scheduled and record-triggered flows.
-
Configure the Start element.
Option Description Object The source object whose records are to be invoiced Trigger The type of record change that triggers the flow Conditions The use case-specific trigger conditions, one or more filter criteria for evaluating certain field values Optimize for Actions and Related Records -
Click and add the following Action element.
Option Description Action The Apex action to call, must be Create Invoice from GIR (single source)Input Values Source Record Id: the ID of the record to be invoiced, usually {!$Record.Id}
Filter Name: only required to disambiguate if the source object has more than one generic filter
Invoice Date: defaults to the current date if empty
Period Start Date and Period End Date: the billing period, required for recurring filtersSpecify a label and an API name as required.
For details about the individual parameters, see Create Invoice from GIR.
-
Add a Fault connector to the Action element.
A configuration problem – an ambiguous filter, or a recurring filter without a billing period – does not come back as data. It makes the action fail, and no invoice is created for any of the passed records.
Without a Fault connector, a screen flow displays the default Salesforce error screen, while an autolaunched or record-triggered flow fails silently to the debug log.
Route the fault path as required – for example, to an error screen that displays
{!$Flow.FaultMessage}, which holds the exact reason. -
Click Save.
Specify a label and an API name as required.
-
Click Activate.
When the defined conditions are met, JustOn Billing & Invoice Management starts creating the invoice for the triggering record.
For help about creating flows, see Flows in the Salesforce Help.
Processing Result
The action returns a collection of results, one per passed record, each holding a chain ID. Depending on your use case, you may need to evaluate it in the flow.
| Chain ID | Meaning |
|---|---|
| set | The invoice creation has been started. Store the value to track the progress or to correlate the invoice with the source record. |
| blank | There is nothing to bill – the record already has a live invoice. This is a valid outcome, not an error. |
To branch on this distinction, add a Decision element that checks whether the chain ID is empty.
Note
The invoice is not available immediately – the action starts an asynchronous process and returns before the invoice exists.
If a subsequent step needs the invoice, track the chain ID, or read the ON_Invoice field of the source record once the processing has finished.
Info
If your flow passes multiple records, the result collection may hold multiple different chain IDs – the software groups the records by filter and dates, and starts one chain per group. Handle the chain ID per record, not as a single value.
For details, see Chain Grouping.