What it is
An Apex test suite, plus the generators behind it, for the 46 record-triggered automations of a Salesforce-based claims management platform (Riskonnect) at DSV. Each test creates claims in a sandbox, lets every automation fire, and checks the result against an independent model of the business rule — an oracle — then rolls everything back. A priority-1 incident brought me into the platform. Fixing it showed me there was no safety net at all, so I proposed permanent changes to how we work on it, and this harness for the claims process is the main one. It grew into a release gate, rehearsed from sandbox to UAT. Making it mandatory for every production deploy is in progress.
Zoom
Why it exists
- No safety net. Changes to the claim automations were checked by hand in a sandbox. A single run-order setting once broke API claim registrations in production — and also silently saved wrong flags on another claim type.
- Behaviour lived only in the UI. The 46 automations had no specification outside the flow builder, so "correct" was whatever the flow currently did.
- Sandboxes had drifted from production. A green test in a sandbox did not prove much about production.
- Known defects existed. Some business rules were known to be wrong but could not be fixed straight away; a naïve suite would either stay red forever or hide them.
What I built
- As-implemented specifications generated from the org metadata for all 46 automations — triggers, entry conditions, run order, formulas, field updates.
- Business-rule oracles written independently of the flows: amount chain, liability limits, time bar, freight cost, applicable law, deductible, routing — 11 in total.
- Apex test classes that insert claims, let every automation run, and assert the stored values against the oracles. All inserts roll back, so the suite can run in any org without leaving data behind.
- Known-defects register. Each known defect is isolated in its own class, so the gate stays green and honest.
- Release gate. A deploy script runs the suite inside the deployment and rolls back on any failure. I rehearsed it six times in UAT, with forced failures: 3 blocked, 3 passed. Making it mandatory for every deploy is in progress.
- Drift detector (Python, manifest-driven) that retrieves metadata from sandbox and production, produces drift reports, and backed the alignment of the partial sandbox to production plus a post-refresh checklist.
Zoom
Key decisions & tradeoffs
Oracles, not snapshots. Snapshot-style tests ("the flow produced X last time") would have frozen the existing defects in place. Writing each rule independently means the tests describe what the business expects, and disagreement is a finding, not noise.
Known defects are first-class. Instead of skipping or deleting tests that would fail, each defect lives in its own class, listed in the register. The gate stays usable and the defect stays visible.
Generate, don't hand-write, the boring parts. Specifications and threshold matrices are generated from metadata, so the suite follows the org instead of a document that goes stale.
Guard-railed AI-assisted development. Much of the generation and test writing was done with an AI coding assistant under strict limits: it works only in a sandbox, never in production, and every UAT/production action is run by a person with their own login.
Same method, other uses
- Routing robot validation. The routing rules were rebuilt as a data-driven checker and replayed against production field history: 3,000+ routings, 98.8 % match against the values at routing time and 99.4 % after including later user corrections. The remaining residue pointed to one real rule defect, documented for the business.
- Regression on a later defect. A "flag cleared on edit" defect was reproduced, fixed in two flows and covered by 20 new tests (40 checks) written failing first, together with an impact analysis of the affected production records.
Results
- 634 test methods covering 46 automations; a whole run takes about 4 minutes.
- 8 defects nobody had reported surfaced while building the suite.
- 11 business-rule oracles and a known-defects register that keep the gate both green and honest.
- Drift detected and corrected across 3 orgs, with a post-refresh checklist so it stays that way.
- 143 generated cases verified the incident fix in two sandboxes before production.
Stack
Salesforce (record-triggered flows, Apex, SOQL), Metadata / Tooling APIs, Salesforce CLI, Python, PowerShell, Git.
Status
- In use on the claims platform (2026); the deploy gate was rehearsed six times, and making it mandatory for every deploy is in progress.
- Related: Incident Response — Null Formula vs. Trigger Order (where it started), role page.
- No company data, customer names, amounts or internal identifiers are published here; counts are technical (tests, automations, routings).