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;