Skip to content

API_Dispatcher

Class · Group: Web Services

apex
global inherited sharing class API_Dispatcher

Factory class for orchestrating the execution of web service handlers. Manages the lifecycle of API calls, including handler initiation, error handling, and change commitment. Supports both single and batch processing of web service requests.

Example

apex
// Process an inbound REST service
API_Dispatcher.processInboundService(API_UpdateInvoice.class.getName());
// Execute an outbound API call
ApiCall__c apiCall = TST_Factory.newOutboundApiCall('API_SendEmail', recordId, parameters);
API_Base handler = API_Dispatcher.execute(apiCall);

Methods

MethodDescription
global static API_Base execute(ApiCall__c apiCall)Executes a single API callout for the provided API call record.
global static List<API_Base> execute(List<ApiCall__c> apiCalls)Processes a list of API callout requests by executing multiple web service handlers.
global static API_Base processInboundService(String serviceName)Processes a single inbound web service request by executing the specified handler.

execute

apex
global static API_Base execute(ApiCall__c apiCall)

Executes a single API callout for the provided API call record.

Parameters

ParameterTypeDescription
apiCallApiCall__cA ApiCall__c record containing details of the API call to execute.

Returns API_Base — The API_Base handler that processed the request, or null if no handler was executed.

Example

apex
ApiCall__c apiCall = TST_Factory.newInboundApiCall('MyServiceHandler');
API_Base handler = API_Dispatcher.execute(apiCall);
apex
global static List<API_Base> execute(List<ApiCall__c> apiCalls)

Processes a list of API callout requests by executing multiple web service handlers. Manages batch processing, commits successful transactions, and logs failures for retries.

Parameters

ParameterTypeDescription
apiCallsListA list of ApiCall__c records representing API calls to process.

Returns API_Base — A list of API_Base handlers that successfully processed the requests.

Example

apex
List<ApiCall__c> apiCalls = [SELECT Id, Service__c FROM ApiCall__c WHERE Status__c = 'Pending'];
List<API_Base> handlers = API_Dispatcher.execute(apiCalls);

processInboundService

apex
global static API_Base processInboundService(String serviceName)

Processes a single inbound web service request by executing the specified handler.

Parameters

ParameterTypeDescription
serviceNameStringThe name of the web service handler class to execute.

Returns API_Base — The API_Base handler that processed the request, or null if no handler was executed.

Example

apex
API_Base handler = API_Dispatcher.processInboundService('MyServiceHandler');