In this article (6 sections)
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.