/** * Sends one synthetic probe and reports the HTTP outcome. * The caller owns persistence, business-result checks and any retry policy. */ public with sharing class IntegrationProbeClient { private static final String ENDPOINT = 'callout:Integration_Target'; private static final Integer TIMEOUT_MS = 10000; public enum Outcome { HTTP_SUCCESS, HTTP_ERROR, NO_RESPONSE } public class InvalidInputException extends Exception {} public class Result { public Outcome outcome { get; private set; } public Integer statusCode { get; private set; } public Result(Outcome outcome, Integer statusCode) { this.outcome = outcome; this.statusCode = statusCode; } } public static Result sendProbe(String operationId) { if (String.isBlank(operationId)) { throw new InvalidInputException('An operation identifier is required.'); } HttpRequest request = buildRequest(operationId); try { HttpResponse response = new Http().send(request); Integer code = response.getStatusCode(); // A 2xx response describes HTTP success, not business completion. Outcome outcome = code >= 200 && code < 300 ? Outcome.HTTP_SUCCESS : Outcome.HTTP_ERROR; return new Result(outcome, code); } catch (CalloutException calloutFailure) { // No final response: do not infer rollback or replay automatically. return new Result(Outcome.NO_RESPONSE, null); } } private static HttpRequest buildRequest(String operationId) { HttpRequest request = new HttpRequest(); request.setEndpoint(ENDPOINT); request.setMethod('POST'); request.setTimeout(TIMEOUT_MS); request.setHeader('Content-Type', 'application/json'); // Receiver-defined tracing header; this alone provides no deduplication. request.setHeader('X-Operation-Id', operationId); request.setBody(JSON.serialize(new Map{ 'testOnly' => true, 'operationId' => operationId })); return request; } }