API_Base
Class · Group: Web Services
global abstract inherited sharing class API_Base extends DML_TransactionExtends: DML_Transaction
Known Derived Types: API_CallCurrentOrg, API_Inbound, API_Outbound
Base class for all API web service calls (outbound and inbound). Provides common functionality for HTTP request handling, error management, and data persistence.
Since: 1.0
Example:
public class API_MyService extends API_Outbound
{
global override void configure()
{
super.configure();
requestPayload = new DTO_Request();
}
}Properties
| Property | Description |
|---|---|
| global ApiCall__c apiCall | The ApiCall__c object that initiated the service call. |
| global String correlationId | The unique correlation ID for this handler instance. |
| global String errorText | Returns errors encountered during the request or the error payload if no error is logged. |
| global enum HttpMethod | HTTP method verbs for web service calls. |
| global DTO_NameValues inputs | DTO containing parameters passed to the API. |
| global API_Base.ServiceCallResult result | Tracks the request, response, and status of a web service call. |
| global ApiSetting__mdt setting | API settings metadata for this service, lazy-loaded from ApiSetting__mdt. |
| global enum WebserviceStatus | Enum representing the status of a web service call. |
Methods
| Method | Description |
|---|---|
| global virtual void configure() | Initializes global variables and timers. |
| global virtual String getBody() | Returns the HTTP request body. |
| global abstract String getEncoding() | Returns the HTTP character encoding. |
| global virtual API_Base.HttpMethod getHttpMethod() | Returns the HTTP method for the service. |
| global virtual List getValidationErrors() | Determines if the web service request should be aborted. |
| global virtual void handleError(Exception exceptionThrown) | Handles errors encountered during the service call. |
| global virtual Boolean isDisabled() | Checks if the API is disabled for the current user. |
| global virtual void onSuccess() | Registers database changes after a successful call. |
Inner Classes
| Class | Description |
|---|---|
| ServiceCallResult | Tracks the request, response, and status of a web service call. |
Property Details
apiCall
global ApiCall__c apiCallType: ApiCall__c
The ApiCall__c object that initiated the service call.
Since:
Example:
correlationId
global String correlationIdType: String
The unique correlation ID for this handler instance.
Since:
Example:
errorText
global String errorTextType: String
Returns errors encountered during the request or the error payload if no error is logged.
Since:
Example:
inputs
global DTO_NameValues inputsType: DTO_NameValues
DTO containing parameters passed to the API.
Since:
Example:
result
global API_Base.ServiceCallResult resultType: API_Base.ServiceCallResult
Tracks the request, response, and status of a web service call.
Since:
Example:
setting
global ApiSetting__mdt settingType: ApiSetting__mdt
API settings metadata for this service, lazy-loaded from ApiSetting__mdt.
Since:
Example:
Method Details
configure
global virtual void configure()Initializes global variables and timers. Override this method to configure DTOs, mock types, timeouts, and other service-specific settings.
Since: 1.0
Example:
global override void configure()
{
super.configure();
requestPayload = new DTO_Request();
responsePayload = new DTO_Response();
defaultMockBody = '{"success": true}';
}getBody
global virtual String getBody()Returns the HTTP request body.
Returns: String - String The request body, empty by default.
Since: 1.0
Example:
global override String getBody()
{
return requestPayload.serialize();
}getEncoding
global abstract String getEncoding()Returns the HTTP character encoding.
Returns: String - String The encoding scheme, must be implemented by subclasses.
Since: 1.0
Example:
global override String getEncoding()
{
return 'application/xml';
}getHttpMethod
global virtual API_Base.HttpMethod getHttpMethod()Returns the HTTP method for the service.
Returns: API_Base.HttpMethod - The HTTP method enum value, or null by default.
Since: 1.0
Example:
global override HttpMethod getHttpMethod()
{
return HttpMethod.GET;
}getValidationErrors
global virtual List<String> getValidationErrors()Determines if the web service request should be aborted. Returns a list of validation error messages. Subscribers override this to add custom validation. Framework validation is handled internally by performValidation() — no super call needed.
Returns: String - A list of error messages. Empty list means validation passed.
Since: 1.0
Example:
global override List<String> getValidationErrors()
{
List<String> errors = new List<String>();
if(String.isBlank(apiCall.TriggeringRecordId__c))
{
errors.add('Triggering record is required');
}
return errors;
}handleError
global virtual void handleError(Exception exceptionThrown)Handles errors encountered during the service call.
Parameters:
exceptionThrown(Exception) - The exception to handle.
Since: 1.0
Example:
global override void handleError(Exception exceptionThrown)
{
super.handleError(exceptionThrown);
// custom error handling
}isDisabled
global virtual Boolean isDisabled()Checks if the API is disabled for the current user. Override to add custom disable logic.
Returns: Boolean - Boolean True if the API is disabled, otherwise false.
Since: 1.0
Example:
global override Boolean isDisabled()
{
return super.isDisabled() || customDisableCheck();
}onSuccess
global virtual void onSuccess()Registers database changes after a successful call.
Since: 1.0
Example:
global override void onSuccess()
{
super.onSuccess();
doUpdate(updatedRecord);
}