UTIL_AsyncChain.ApiStep
Class
global inherited sharing class UTIL_AsyncChain.ApiStep extends UTIL_AsyncChain.ChainStepExtends: 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
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
| Method | Description |
|---|---|
| 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
global UTIL_AsyncChain.ApiStep credential(String namedCredential)Overrides the Named Credential used for this API call.
Parameters
| Parameter | Type | Description |
|---|---|---|
namedCredential | String | The Named Credential developer name. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
.credential('AlternateGateway')triggeringRecord
global UTIL_AsyncChain.ApiStep triggeringRecord(Id recordId)Sets a static triggering record ID for this API call.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | Id | The Salesforce record ID. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
.triggeringRecord(account.Id)triggeringRecordFrom
global UTIL_AsyncChain.ApiStep triggeringRecordFrom(String contextKey)Sets the triggering record ID from a ChainContext key, resolved at execution-time.
Parameters
| Parameter | Type | Description |
|---|---|---|
contextKey | String | The ChainContext key containing the record ID. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
.triggeringRecordFrom('orderId')withParameter
global UTIL_AsyncChain.ApiStep withParameter(String name, String value)Adds a static parameter value to pass to the handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | String | The parameter name (use the handler's PARAM_* constants). |
value | String | The parameter value. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
.withParameter(API_ChargePayment.PARAM_AMOUNT, '99.99')
.withParameter(API_ChargePayment.PARAM_CURRENCY, 'USD')withParameterFrom
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
| Parameter | Type | Description |
|---|---|---|
parameterName | String | The handler parameter name. |
contextKey | String | The ChainContext key to read the value from. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_SendConfirmation.class)
.withParameterFrom('recipient', 'customerEmail')withRetry
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
| Parameter | Type | Description |
|---|---|---|
maxAttempts | Integer | Total attempts including the first (2 = one retry). Null or <= 1 disables. |
baseBackoffSeconds | Integer | Base delay fed to UTIL_Retry.exponential(); null = 0. |
Returns UTIL_AsyncChain.ApiStep — This ApiStep for method chaining.
Example
new UTIL_AsyncChain.ApiStep(API_ChargePayment.class)
.triggeringRecordFrom('orderId')
.withRetry(3, 30)work
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
| Parameter | Type | Description |
|---|---|---|
context | UTIL_AsyncChain.ChainContext | Shared chain context for reading configuration and writing results. |
Returns UTIL_AsyncChain.StepResult — StepResult indicating success or failure of the API call.
Constructors
| Constructor | Description |
|---|---|
| global ApiStep(Type handlerType) | Creates an ApiStep that wraps the specified API_Outbound handler. |
ApiStep(Type handlerType)
global ApiStep(Type handlerType)Creates an ApiStep that wraps the specified API_Outbound handler.
Parameters
| Parameter | Type | Description |
|---|---|---|
handlerType | Type | The API_Outbound subclass to execute (e.g., API_SendEmail.class). |
Example
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
.withParameter(API_SendEmail.PARAM_RECIPIENT, 'test@example.com')
.triggeringRecordFrom('recordId')