Skip to content
All builds
BULK-SAFE DECISIONS

Apex Routing Engine

A deterministic Invocable Apex contract for routing requests by type, product, risk and active metadata rules—without hiding orchestration inside code.

Invocable ApexCustom MetadataQueueable ApexBulk processingApex tests
Interactive demo

Sample build using synthetic data in a Developer Edition org. Created to demonstrate architecture and delivery approach; not presented as client work.

Launch the demo
The scenario

A designed problem, not a client claim.

DemoCo routing has enough combinations, fallbacks and tie-breaks that adding branches to Flow makes the decision difficult to test and change safely.

Before · Messy process
  • Nested Flow decisions repeat matching rules.
  • Fallback behavior varies across paths.
  • Bulk execution and one-to-one results are hard to reason about.
  • Rule changes require editing orchestration.
After · Reliable system
  • One Invocable contract accepts Case IDs and returns one result per input.
  • Active Custom Metadata controls matching and priority.
  • Deterministic tie-breaking makes identical inputs reproducible.
  • Flow remains responsible for Case updates and user-visible outcomes.
Interactive system demo

Watch the system make the decision.

Choose a scenario, play the full path or inspect any decision directly. This is an explainable frontend model, not a live Salesforce connection.

Choose a path4 deterministic scenarios
Live system mapDECISION ENGINE
Interactive frontend modelStep 1 / 5No live org connection
Architecture

Clear responsibilities. Explicit contracts.

01

Input contract

A list of Case IDs enters a bulk-safe invocable method.

02

Query layer

Cases, active rules and queue references are loaded once into maps.

03

Pure matcher

Eligible rules are scored and sorted with a deterministic tie-break.

04

Result contract

Each input receives ROUTED, FALLBACK, NEEDS_INPUT or ERROR plus safe context.

05

Queueable audit

Non-critical audit events are persisted outside the routing decision.

Design decisions

Why the system is shaped this way.

No Case DML in the engine

The action returns a decision; Flow retains control of the transaction and record updates.

One result per input

The contract preserves order and makes partial input problems explicit instead of failing the batch opaquely.

Configuration is still validated

Metadata makes rules changeable, not automatically safe; missing queues return controlled errors.

Production hardening

What changes before real users depend on it.

  • Exercise exact match, ties, inactive rules, incomplete input and unavailable capacity.
  • Verify stable results for duplicate IDs and a 200-Case transaction.
  • Protect the async audit path from retries that create duplicate events.
  • Log configuration identifiers without exposing Case content.
Have a similar process?

Let's map the risk before adding automation.