Revenue Cloud project notebook, written by two Meir IT consultants who implement it.

What is Revenue Cloud?

Billing and Tax·Admin

The Apex Tax Engine Adapter

The standard tax engine accepted requests and returned zero, so the team wrote an internal Apex adapter that reads rates from the org. What it must return, and the eight failures before the first taxed invoice.

Nathan Altmann · Revenue Cloud consultant at Meir IT

Published 3 min read

In 3 linesfor leadership

  1. Invoices had to go out with tax, but the standard tax engine returned zero without any error.
  2. A custom adapter produced taxed invoices, after eight failures that all showed up as zero tax.
  3. The cost is code to test and maintain; the article advises trying plain configuration first.
In this article (6 sections)
  1. The problem
  2. The solution
  3. Setting it up
  4. The choice and its cost
  5. In practice
  6. Sources

The problem

Step: tax calculation on the invoice. The client had several legal entities with different tax rules, rates already held in an existing table, and no external tax provider in scope. Invoices had to come out taxed from those rates.

On the org under test, the standard tax engine computed nothing: it accepted the request and returned zero. At the time, a custom adapter looked like the only way to get a taxed invoice. With no external provider, that adapter is purely internal: an Apex class that reads the rates from the org and hands them back to the engine.

The solution

What makes this adapter long to get right is how the engine reads its answer. It accepts any structurally valid response, and reads zero for every piece that is missing: the amount details, the taxable flag, the response addresses, the header totals. Each omission produces the same symptom as the previous one, a tax of zero with no error, so a from-scratch adapter turns into a long series of failures that all look alike.

Hence the rule: start from an adapter that already runs, and change it one piece at a time. The class implements the tax adapter interface and is registered through a provider and an engine. The engine type that works requires a named credential (the stored address and login of an outside service), a seller code and engine address fields, even though the adapter never leaves the org. A dummy named credential is enough.

Setting it up

The order that works: permissions first, then engine registration, then the class, then the data, then a real transaction. Each of these can fail in a way that looks like the previous one, so test after each step.

The choice and its cost

The adapter did produce taxed invoices, and the price of that choice is Apex. It needs a test class and org coverage before it can reach production. On one project, the request-processing entry point turned out to be untestable, because Salesforce exposes no constructor for its request classes. That capped coverage and became the real blocker to deployment.

What I would do again: first check whether the rule fits in rate rows plus a treatment on the line, and keep the adapter for cases where that configuration is not enough. Country-Driven Tax Code, Without Apex solved a similar problem with no Apex at all.

In practice

  • Try configuration first: rate rows plus a treatment on the line.
  • Start from an adapter that already runs, never from scratch.
  • Follow the order: permissions, engine, class, data, transaction, and test after each step.
  • Measure test coverage in the first week, before the adapter becomes the thing blocking the release.

Sources

  1. TaxEngine
  2. TaxEngineProvider
  3. Billing Fields on TaxRate
  4. CommerceTax Namespace
A technical question about this article?

A question about this article? I reply within 48 hours.

Something unclear, a mistake, or different behavior in your Salesforce org? Write to me.

Prefer email? Write to nathan@meir-it.com

Get notified of new articles

Type at least two letters.