In this article (8 sections)
Stage: invoicing a renewal order. The client, a SaaS software company, had just moved from CPQ and Salesforce Billing to Revenue Cloud and Revenue Cloud Billing. The first renewal orders were activated. On one of them, accounting clicks "Generate Invoices" and gets: “We can't generate invoices because there are no billing schedules.” None of the renewal lines had a billing schedule.
The error the flow was hiding
Billing schedules are created when the order is activated, by a flow: Order To Billing Schedule Flow. It sends the lines to the billing context (BillingContext__stdctx, mapping OrderEntitiesMapping), which builds the schedules. On failure, the flow goes through an error element that posts the message to the order's feed.
Feeds weren't enabled on the Order object. So the post failed too, and the flow interview details only showed that second error: Order is not enabled for feeds. The real cause showed up nowhere.
To see it, the billing action had to be called directly, in preprod, with the same lines the flow sent. Then the message came out: DateTimeParseException: Text '…T00:00:00.000Z' could not be parsed.
A datetime where the engine expects a date
In an order, renewal lines are the only ones carrying OrderItemDetail records, which hold the net price of the renewed period. Their EffectiveFrom and EffectiveTo fields are datetimes. The billing context reads them and expects dates. It fails for the whole order as soon as one Renew line is in the batch. Nothing in the configuration changes that format: it's a platform defect.
Why "Renew" couldn't work here
The next idea was to send the lines another way, through the standalone context used by the Create Standalone Billing Schedules API, with the native Renew action type. The engine refuses: Create a billing schedule for the original transaction…
This is what matters for any migration project. In Revenue Cloud Billing, a renewal extends the billing schedule of the original sale. It needs that original sale, billed in Revenue Cloud Billing. Here, the original sales were the takeover orders created during the migration, with a "already billed" checkbox: the old system, Salesforce Billing, had invoiced them. They have no schedule in Revenue Cloud Billing and never will.
The result: in the first year after cutover, almost every renewal hits this, each on its anniversary date. Nothing shows on go-live day. The problem arrives one renewal at a time, as activated orders nobody can invoice.
The fix: bill the renewed period as a sale
The Add action type creates a fresh schedule, as for a term-defined sale, without looking for an original sale. For the invoice, the result is the same: the renewed period, at the renewal net price, at the right frequency. What you lose is the chain: the schedule doesn't show up as the continuation of the previous one.
With Add, the engine requires fields it fills in itself on the standard path. The list was built one try at a time, on the same line:
| Try | What was added | Result |
|---|---|---|
| 1 | The line alone: product, period, quantity, price, frequency | rejected |
| 2 | BillingActionType = Renew | rejected: Create a billing schedule for the original transaction… |
| 3 | BillingActionType = Add | rejected |
| 4 | BillingStartMonth, BillingDayOfMonth, PeriodBoundary = Anniversary | rejected |
| 5 | Billing and shipping addresses | rejected: Specify an amount |
| 6 | TotalPrice | schedule created, ready for invoicing |
The start day and month come from the start date of the renewed period, with anniversary billing: those are the settings the native flow puts on the schedule groups it creates. The month goes as text ("1" to "12"), the day as a number.
The fix in the org
An invocable Apex class builds the transactions. For each Renew line of an order, excluding takeover lines already billed, it takes the renewal net price from the OrderItemDetail, the period, the frequency, then the order's addresses, legal entity, tax and billing treatment:
// One transaction per Renew line with no schedule (standalone context)
t.put('BillingActionType__std', 'Add');
t.put('BillingTermUnit__std', TERM_UNIT.get(oi.BillingFrequency2)); // Monthly → Month…
t.put('BillingTerm__std', 1);
t.put('PeriodBoundary__std', 'Anniversary');
t.put('BillingDayOfMonth__std', oi.ServiceDate.day());
t.put('BillingStartMonth__std', String.valueOf(oi.ServiceDate.month())); // "1" to "12"
t.put('StartDate__std', String.valueOf(oi.ServiceDate)); // a date, not a datetime
t.put('EndDate__std', String.valueOf(oi.EndDate));
t.put('NetUnitPrice__std', detail.NetUnitPrice); // renewal net price
t.put('TotalPrice__std', detail.TotalPrice.setScale(2, RoundingMode.HALF_UP));
// … then the order addresses, legal entity, tax and billing treatment
return JSON.serialize(new Map<String, Object>{ 'Transaction' => transactions });Addresses go through JSON.serialize, not text concatenation in the flow. Hundreds of orders had a street on two lines, and a raw line break inside a string makes the JSON invalid.
In the flow, three changes:
- Renew lines are taken out of the batch sent to the standard billing context;
- right after the loop over the lines, the flow calls the class, then the
createBillingSchedulesFromTrxnaction withStandaloneBillingContext__stdctx,TransactionMappingto read andBSGEntitiesMappingto save; - that call runs before the other lines: if those fail, the renewals already have their schedule.
Never create the same schedule twice
A billing schedule can't be deleted. A duplicate stays in the org and can end up as a double invoice. So the class reads existing schedules (BillingSchedule.ReferenceEntityItemId) and skips any line that already has one.
That check makes re-runs safe. It also covers the catch-up: orders already activated go through a script that first shows what it will create, and only creates with an explicit option.
What testing showed
In preprod: a single annual line, an eleven-line order with ten bundle components at zero, a line priced monthly and billed quarterly, and a full run through the UI (asset, Renew, quote, order linked to the original contract, activation). The flow fired on its own, every line got its schedule, and the draft invoice had the right period and tax. Run again on an order already processed, the class created nothing.
In practice
- Turn on Feed Tracking for Order, or replace the flow's error element with a record in a log object. Otherwise, billing errors stay invisible.
- When a billing flow fails, replay the action by hand with the same data. The engine's message is often more precise than the flow's.
- Before a CPQ to Revenue Cloud cutover, list the contracts renewing within twelve months and run a full renewal on one of them in a sandbox, all the way to the draft invoice.
- For a line sent as
Add, keep the list of fields from the table above: a failed try only names one missing field at a time. - Any action that creates schedules checks for existing ones first. Running it twice must create nothing more.
For the full path from order to invoice, see From order to invoice. For the migration method, Migrate from CPQ to Revenue Cloud. The same story told for leadership: Renewals signed, and nobody could invoice them.