← Back home

Case study

Salesforce UoW Position Array Orchestration

Engineered a dependency-aware Apex orchestration framework that extends classic Unit of Work with mirrored position arrays, staged error contracts, and compliance-aware quarantine flows.

Challenge

Standard Unit of Work patterns did not reliably handle cross-entity dependency failures, duplicate/PII compliance checks, or resilient continuation rules across high-volume parent-child transaction chains.

Solution

Introduced a dual-position array model where execution entities and staging records share stable index alignment. Each `entity_proc_srvc` reads a centralized `json_errors__c` contract, skips only dependency-blocked branches, and proceeds with independent work. A final staging persistence service commits aggregated outcomes to the database, while wrapper classes encapsulate entity-specific transformations and a core service enforces duplicate detection plus PII quarantine for matched accounts and sibling records.

Impact

Reduced cascade failures, improved auditability of partial-success runs, and established a reusable orchestration pattern for deterministic DML, safer compliance handling, and faster operational triage.

Stack

SalesforceApexUnit of WorkPlatform EventsObservability

Unit-of-Work State Orchestration

Visualizes mirrored execution and staging arrays, dependency gating through `json_errors__c`, and final staging persistence for deterministic DML with auditable outcomes.

Dependency gate with shared error contract

if (DependencyGate.shouldSkip(currentEntity, stageRows[i].json_errors__c)) {
    stageRows[i].Status__c = 'Skipped';
    stageRows[i].json_errors__c = ErrorContract.append(
        stageRows[i].json_errors__c,
        'DEPENDENCY_BLOCK',
        'Upstream dependency failed for ' + currentEntity
    );
    continue;
}

Dual position arrays + deterministic capture

List<SObject> orderedParents = buildOrderedParents(payload);
List<Pipeline_Stage__c> stageRows = buildMirroredStageRows(orderedParents);

for (Integer i = 0; i < orderedParents.size(); i++) {
    SaveResult sr = upsertScoped(orderedParents[i]);
    stageRows[i].Status__c = sr.isSuccess() ? 'Success' : 'Failed';
    stageRows[i].Error__c = sr.isSuccess() ? null : sr.getErrors()[0].getMessage();
}

update stageRows;