Skip to content

UTIL_AsyncChain.ApiStep

Class

apex
global inherited sharing class UTIL_AsyncChain.ApiStep extends UTIL_AsyncChain.ChainStep

Extends: UTIL_AsyncChain.ChainStep

Known Derived Types: IF_Chain.Step.work(UTIL_AsyncChain.ChainContext)

Chain step adapter that executes any API_Outbound handler as part of an async chain. Wraps the full web service lifecycle (validation, callout, response parsing, DML, ApiCall__c persistence) via UTIL_HttpClient delegation mode, allowing existing outbound services to run inside chains with zero changes to the service class. Configuration is stored in the ChainContext (not on the step instance) because steps are serialized as class names and instantiated via reflection. At build-time, the ChainBuilder calls writeConfig() to persist the step's configuration into the initial context. At execution-time, work() reads the configuration back from the context using the current step index.

Example

apex
UTIL_AsyncChain.newChain('OrderProcessing')
    .withInitialContext('orderId', order.Id)
    .then(new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
        .triggeringRecordFrom('orderId')
        .withParameter(API_ChargePayment.PARAM_AMOUNT, '99.99'))
    .then(new UTIL_AsyncChain.ApiStep(API_SendConfirmation.class)
        .triggeringRecordFrom('orderId')
        .withParameterFrom('recipient', 'customerEmail'))
    .onError(new NotifyAdminStep())
    .execute();

Methods

MethodDescription
global UTIL_AsyncChain.ApiStep credential(String namedCredential)Overrides the Named Credential used for this API call.
global UTIL_AsyncChain.ApiStep triggeringRecord(Id recordId)Sets a static triggering record ID for this API call.
global UTIL_AsyncChain.ApiStep triggeringRecordFrom(String contextKey)Sets the triggering record ID from a ChainContext key, resolved at execution-time.
global UTIL_AsyncChain.ApiStep withParameter(String name, String value)Adds a static parameter value to pass to the handler.
global UTIL_AsyncChain.ApiStep withParameterFrom(String parameterName, String contextKey)Maps a handler parameter to a ChainContext key, resolved at execution-time.
global UTIL_AsyncChain.ApiStep withRetry(Integer maxAttempts, Integer baseBackoffSeconds)Opt-in chain-level retry for this API step.
global override UTIL_AsyncChain.StepResult work(UTIL_AsyncChain.ChainContext context)Executes the API_Outbound handler via UTIL_HttpClient delegation mode.

credential

apex
global UTIL_AsyncChain.ApiStep credential(String namedCredential)

Overrides the Named Credential used for this API call.

Parameters

ParameterTypeDescription
namedCredentialStringThe Named Credential developer name.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
    .credential('AlternateGateway')

triggeringRecord

apex
global UTIL_AsyncChain.ApiStep triggeringRecord(Id recordId)

Sets a static triggering record ID for this API call.

Parameters

ParameterTypeDescription
recordIdIdThe Salesforce record ID.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
    .triggeringRecord(account.Id)

triggeringRecordFrom

apex
global UTIL_AsyncChain.ApiStep triggeringRecordFrom(String contextKey)

Sets the triggering record ID from a ChainContext key, resolved at execution-time.

Parameters

ParameterTypeDescription
contextKeyStringThe ChainContext key containing the record ID.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
    .triggeringRecordFrom('orderId')

withParameter

apex
global UTIL_AsyncChain.ApiStep withParameter(String name, String value)

Adds a static parameter value to pass to the handler.

Parameters

ParameterTypeDescription
nameStringThe parameter name (use the handler's PARAM_* constants).
valueStringThe parameter value.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
    .withParameter(API_ChargePayment.PARAM_AMOUNT, '99.99')
    .withParameter(API_ChargePayment.PARAM_CURRENCY, 'USD')

withParameterFrom

apex
global UTIL_AsyncChain.ApiStep withParameterFrom(String parameterName, String contextKey)

Maps a handler parameter to a ChainContext key, resolved at execution-time. Use this when the parameter value is produced by a prior step in the chain.

Parameters

ParameterTypeDescription
parameterNameStringThe handler parameter name.
contextKeyStringThe ChainContext key to read the value from.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_SendConfirmation.class)
    .withParameterFrom('recipient', 'customerEmail')

withRetry

apex
global UTIL_AsyncChain.ApiStep withRetry(Integer maxAttempts, Integer baseBackoffSeconds)

Opt-in chain-level retry for this API step. When configured, the chain re-runs the whole step (a fresh callout) with exponential backoff, and the outbound engine's own NextRetry__c rescheduling is suppressed for calls made by this step — one retry authority, never two. Without this call the outbound engine keeps sole ownership of retries, exactly as before.

Parameters

ParameterTypeDescription
maxAttemptsIntegerTotal attempts including the first (2 = one retry). Null or <= 1 disables.
baseBackoffSecondsIntegerBase delay fed to UTIL_Retry.exponential(); null = 0.

Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.

Example

apex
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
    .triggeringRecordFrom('orderId')
    .withRetry(3, 30)

work

apex
global override UTIL_AsyncChain.StepResult work(UTIL_AsyncChain.ChainContext context)

Executes the API_Outbound handler via UTIL_HttpClient delegation mode. Reads configuration from the ChainContext, builds the request, invokes the handler, and writes results back to the context for downstream steps.

Parameters

ParameterTypeDescription
contextUTIL_AsyncChain.ChainContextShared chain context for reading configuration and writing results.

Returns UTIL_AsyncChain.StepResult — StepResult indicating success or failure of the API call.

Constructors

ConstructorDescription
global ApiStep(Type handlerType)Creates an ApiStep that wraps the specified API_Outbound handler.

ApiStep(Type handlerType)

apex
global ApiStep(Type handlerType)

Creates an ApiStep that wraps the specified API_Outbound handler.

Parameters

ParameterTypeDescription
handlerTypeTypeThe API_Outbound subclass to execute (e.g., API_SendEmail.class).

Example

apex
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
    .withParameter(API_SendEmail.PARAM_RECIPIENT, 'test@example.com')
    .triggeringRecordFrom('recordId')