In this article (6 sections)
The problem
Step: the tax code on the quote line, which then follows the order and the invoice. The catalog mixed two product families with opposite tax rules. Some products impose their own tax code because the taxable event happens in a specific place, such as where an event is held. The others must take the code of the customer’s country.
The second family broke. A subscription product was pinned to a single tax code. Sold to a customer in another country, no rate matched, and the invoice came out with no tax at all and no error. Event products were fine, which made the bug look random.
The solution
A rate is found from a tax code and a country. When the product’s code has no rate for the customer’s country, the lookup finds nothing, and the invoice goes out untaxed instead of failing. Event products never hit this because their code is supposed to stay fixed wherever the customer is. Only the products whose code should follow the customer were exposed, and only when sold abroad.
The obvious fix would be a setting that changes the code by country, and there is no native one. A tax treatment item (TaxTreatmentItem) carries a product and a tax code, with no geographic field. The standard tax decision table takes a code as input and returns a rate, so it can never produce a code.
The code therefore has to be set on the line before calculation, and survive repricing. What works is TaxPolicy.TreatmentSelection = Manual: a treatment set on the line then drives the calculation and is not derived again.
Setting it up
- Declare the rule on the product. A picklist with two values is enough: the product imposes its code, or the code comes from the customer.
- Keep the tax zone on the account as a picklist maintained by finance, not derived from the address, so finance can override it.
- Set the treatment from a flow when a quote line is created or updated, mapping zone to code.
- Set the policy to Manual so the treatment survives Reprice All.
- Don’t write a second flow for the order. The context service carries the treatment from the quote line to the order item on its own.
The choice and its cost
The flow won over Apex. The other route, a custom Apex tax adapter, needs a test class and enough code coverage to deploy. On one project, coverage was the only thing blocking a production release, so staying out of Apex was worth real money.
In return, Manual selection makes the line the source of truth. If the flow sets the wrong code, nothing downstream corrects it. That puts the weight on the zone-to-code mapping, which finance owns since the tax zone sits on the account.
In practice
- Set the tax code on the line, since no native setting varies it by country.
- Use
TaxPolicy.TreatmentSelection = Manualso repricing keeps your treatment. - Write the zone-to-code mapping as a table, one row per tax zone with the code the flow sets, and have finance sign it.
- Write flow criteria on API values, never on displayed labels.