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.
Since: 1.0
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 ApiStep(Type handlerType) | Creates an ApiStep that wraps the specified API_Outbound handler. |
| 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 override UTIL_AsyncChain.StepResult work(UTIL_AsyncChain.ChainContext context) | Executes the API_Outbound handler via UTIL_HttpClient delegation mode. |
Method Details
ApiStep
global ApiStep(Type handlerType)Creates an ApiStep that wraps the specified API_Outbound handler.
Parameters:
handlerType(Type) - The API_Outbound subclass to execute (e.g., API_SendEmail.class).
Since: 1.0
Example:
new UTIL_AsyncChain.ApiStep(API_SendEmail.class)
.withParameter(API_SendEmail.PARAM_RECIPIENT, 'test@example.com')
.triggeringRecordFrom('recordId')credential
global UTIL_AsyncChain.ApiStep credential(String namedCredential)Overrides the Named Credential used for this API call.
Parameters:
namedCredential(String) - The Named Credential developer name.
Returns: UTIL_AsyncChain.ApiStep - This ApiStep for method chaining.
Since: 1.0
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:
recordId(Id) - The Salesforce record ID.
Returns: UTIL_AsyncChain.ApiStep - This ApiStep for method chaining.
Since: 1.0
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:
contextKey(String) - The ChainContext key containing the record ID.
Returns: UTIL_AsyncChain.ApiStep - This ApiStep for method chaining.
Since: 1.0
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:
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.
Since: 1.0
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:
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.
Since: 1.0
Example:
new UTIL_AsyncChain.ApiStep(API_SendConfirmation.class)
.withParameterFrom('recipient', 'customerEmail')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:
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.
Since: 1.0