Skip to content

UTIL_HttpClient.RequestBuilder ​

Class · Group: Web Services

Learn it: Fast Start - Outbound APIs and Web Services guide

apex
global inherited sharing class UTIL_HttpClient.RequestBuilder

Fluent builder for configuring and executing HTTP requests through API_Dispatcher.

Example

apex
Map<String, Object> result = UTIL_HttpClient.get('MyService', '/status')
   .header('X-Custom', 'value')
   .timeout(30000)
   .asMap();

Methods by task ​

Find a method by what you want to do. A group links to a worked example when a guide has one. Every method is described in the full list below.

GroupMethodsWorked example
Build the requestbody credential header headers method path pathParam queryParam timeoutBuilder Features
Send it and read the answerasMap asString deserialize sendUTIL_HttpClient (Fluent HTTP Client), Status code is 0
Retry, or stop calling a failing systemonFailure retryOn withCircuitBreaker withExponentialBackoff withRetryPer-Call Overrides with UTIL_HttpClient
Hand the call to your own handler classinvoke withParameter withParameters withTriggeringRecordUTIL_HttpClient (Fluent HTTP Client), How do I find the calls made for one record?
Test the call, or set its IDs and loggingskipLogging withCorrelationId withIdempotencyKey withMockResponseMock Mode and API_MockFactory
Replace words in the request or answer bodyreplaceRequestToken replaceRequestTokens replaceResponseToken replaceResponseTokens

Methods ​

MethodDescription
global Map<String, Object> asMap()Executes the request and deserializes the response body as an untyped Map.
global String asString()Executes the request and returns the response body as a String.
global UTIL_HttpClient.RequestBuilder body(Object requestBody)Sets the request body by JSON-serializing the provided object.
global UTIL_HttpClient.RequestBuilder body(String requestBody)Sets the request body as a raw string.
global UTIL_HttpClient.RequestBuilder credential(String credential)Sets the Named Credential for the endpoint.
global Object deserialize(Type responseType)Executes the request and deserializes the response body into the specified type.
global UTIL_HttpClient.RequestBuilder header(String name, String value)Adds a single header to the request.
global UTIL_HttpClient.RequestBuilder headers(Map<String, String> headerMap)Adds multiple headers to the request.
global API_Outbound invoke()Executes in delegation mode and returns the delegate handler instance.
global UTIL_HttpClient.RequestBuilder method(API_Base.HttpMethod httpMethod)Replaces the HTTP method that get, post, put, del or patch chose.
global UTIL_HttpClient.RequestBuilder onFailure(UTIL_HttpClient.FailureAction action)Sets the failure handling strategy.
global UTIL_HttpClient.RequestBuilder path(String urlPath)Replaces the path given before, including the one given to get, post, put, del or patch.
global UTIL_HttpClient.RequestBuilder pathParam(String name, String value)Replaces a {name} placeholder in the URL path with a value.
global UTIL_HttpClient.RequestBuilder queryParam(String name, String value)Adds a query parameter to the request URL.
global UTIL_HttpClient.RequestBuilder replaceRequestToken(String searchToken, String replaceToken)Registers a single request body replacement token.
global UTIL_HttpClient.RequestBuilder replaceRequestTokens(Map<String, String> tokens)Registers multiple request body replacement tokens.
global UTIL_HttpClient.RequestBuilder replaceResponseToken(String searchToken, String replaceToken)Registers a single response body replacement token.
global UTIL_HttpClient.RequestBuilder replaceResponseTokens(Map<String, String> tokens)Registers multiple response body replacement tokens.
global UTIL_HttpClient.RequestBuilder retryOn(Set<Integer> statusCodes)Chooses which HTTP status codes are worth another attempt.
global HttpResponse send()Executes the HTTP request and returns the raw HttpResponse.
global UTIL_HttpClient.RequestBuilder skipLogging()Skips ApiCall__c persistence for this request.
global UTIL_HttpClient.RequestBuilder timeout(Integer milliseconds)Sets how long, in milliseconds, to wait for the external system to answer.
global UTIL_HttpClient.RequestBuilder withCircuitBreaker()Enables circuit breaker protection under the service's own breaker: the credential's breaker for a call built from a credential, the handler's breaker for a call made through useHandler(...).
global UTIL_HttpClient.RequestBuilder withCircuitBreaker(String circuitName)Enables circuit breaker protection under a breaker you name.
global UTIL_HttpClient.RequestBuilder withCorrelationId(String correlationId)Keeps a correlation id with the call.
global UTIL_HttpClient.RequestBuilder withExponentialBackoff(Integer maxRetries, Integer baseBackoffSeconds)Retries a failed request, and makes each scheduled retry wait twice as long as the one before.
global UTIL_HttpClient.RequestBuilder withIdempotencyKey(String idempotencyKey)Sets an explicit idempotency key for duplicate detection.
global UTIL_HttpClient.RequestBuilder withMockResponse(API_MockFactory.MockResponse mockResponse)Sets a mock response to inject at framework level, overriding the handler's own mock.
global UTIL_HttpClient.RequestBuilder withParameter(String name, String value)Adds a request parameter for delegation mode, where your own handler class sends the request.
global UTIL_HttpClient.RequestBuilder withParameters(Map<String, String> parameters)Adds multiple request parameters for delegation mode, where your own handler class sends the request.
global UTIL_HttpClient.RequestBuilder withRetry(Integer maxRetries)Enables synchronous retry with the specified maximum attempts.
global UTIL_HttpClient.RequestBuilder withRetry(Integer maxRetries, Integer backoffSeconds)Enables synchronous retry with a linear backoff.
global UTIL_HttpClient.RequestBuilder withTriggeringRecord(Id recordId)Links this callout to a triggering business record.

asMap ​

apex
global Map<String, Object> asMap()

Executes the request and deserializes the response body as an untyped Map.

Returns Object — The deserialized response as Map of String to Object

Example

apex
Map<String, Object> data = UTIL_HttpClient.get('MyService', '/data').asMap();

asString ​

apex
global String asString()

Executes the request and returns the response body as a String. Answers null when the request produced no response of its own, so an outcome with nothing to read stays distinguishable from a response whose body really is empty.

Returns String — The response body string

Example

apex
String body = UTIL_HttpClient.get('MyService', '/data').asString();

body ​

apex
global UTIL_HttpClient.RequestBuilder body(Object requestBody)

Sets the request body by JSON-serializing the provided object.

Parameters

ParameterTypeDescription
requestBodyObjectThe object to serialize as JSON

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .body(new Map<String, String>{'key' => 'value'})
   .send();
apex
global UTIL_HttpClient.RequestBuilder body(String requestBody)

Sets the request body as a raw string.

Parameters

ParameterTypeDescription
requestBodyStringThe raw body string

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .body('{"key": "value"}')
   .send();

credential ​

apex
global UTIL_HttpClient.RequestBuilder credential(String credential)

Sets the Named Credential for the endpoint.

Parameters

ParameterTypeDescription
credentialStringThe Named Credential name

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.useHandler(API_SendEmail.class)
   .credential('EmailGateway')
   .invoke();

deserialize ​

apex
global Object deserialize(Type responseType)

Executes the request and deserializes the response body into the specified type.

Parameters

ParameterTypeDescription
responseTypeTypeThe Apex Type to deserialize into

Returns Object — The deserialized response object

Example

apex
MyDTO result = (MyDTO)UTIL_HttpClient.get('MyService', '/data')
   .deserialize(MyDTO.class);
apex
global UTIL_HttpClient.RequestBuilder header(String name, String value)

Adds a single header to the request.

Parameters

ParameterTypeDescription
nameStringThe header name
valueStringThe header value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .header('X-Custom', 'value')
   .send();

headers ​

apex
global UTIL_HttpClient.RequestBuilder headers(Map<String, String> headerMap)

Adds multiple headers to the request.

Parameters

ParameterTypeDescription
headerMapMapMap of header names to values

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .headers(new Map<String, String>{'X-Custom' => 'value', 'X-Trace' => 'abc'})
   .send();

invoke ​

apex
global API_Outbound invoke()

Executes in delegation mode and returns the delegate handler instance.

Returns API_Outbound — The executed API_Outbound delegate handler

Example

apex
API_Outbound handler = UTIL_HttpClient.useHandler(API_SendEmail.class)
   .withTriggeringRecord(recordId)
   .invoke();
API_SendEmail.DTO_Response dto = (API_SendEmail.DTO_Response)handler.responsePayload;

method ​

apex
global UTIL_HttpClient.RequestBuilder method(API_Base.HttpMethod httpMethod)

Replaces the HTTP method that get, post, put, del or patch chose. On a request built from a credential, passing null sends the request as POST.

Parameters

ParameterTypeDescription
httpMethodAPI_Base.HttpMethodThe HTTP method enum value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/data')
   .method(API_Base.HttpMethod.PUT)
   .send();

onFailure ​

apex
global UTIL_HttpClient.RequestBuilder onFailure(UTIL_HttpClient.FailureAction action)

Sets the failure handling strategy.

Parameters

ParameterTypeDescription
actionUTIL_HttpClient.FailureActionThe failure action to apply

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .onFailure(UTIL_HttpClient.FailureAction.LOG_FAILURE)
   .send();

path ​

apex
global UTIL_HttpClient.RequestBuilder path(String urlPath)

Replaces the path given before, including the one given to get, post, put, del or patch. The path is added to the credential's endpoint, and it can hold {name} placeholders that pathParam fills in.

Parameters

ParameterTypeDescription
urlPathStringThe URL path to append

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/api')
   .path('/v2/send')
   .send();

pathParam ​

apex
global UTIL_HttpClient.RequestBuilder pathParam(String name, String value)

Replaces a {name} placeholder in the URL path with a value.

Parameters

ParameterTypeDescription
nameStringThe placeholder name (without braces)
valueStringThe replacement value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.get('CRM', '/accounts/{id}')
   .pathParam('id', accountId)
   .send();

queryParam ​

apex
global UTIL_HttpClient.RequestBuilder queryParam(String name, String value)

Adds a query parameter to the request URL.

Parameters

ParameterTypeDescription
nameStringThe parameter name
valueStringThe parameter value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.get('MyService', '/search')
   .queryParam('q', 'test')
   .queryParam('limit', '10')
   .send();

replaceRequestToken ​

apex
global UTIL_HttpClient.RequestBuilder replaceRequestToken(String searchToken, String replaceToken)

Registers a single request body replacement token. The search token in the serialized request body will be replaced with the replace token before sending.

Parameters

ParameterTypeDescription
searchTokenStringThe token to search for in the request body
replaceTokenStringThe token to replace it with

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('PaymentGateway', '/charges')
   .body(chargeRequest)
   .replaceRequestToken('currencyIsoCode', 'currency')
   .send();

replaceRequestTokens ​

apex
global UTIL_HttpClient.RequestBuilder replaceRequestTokens(Map<String, String> tokens)

Registers multiple request body replacement tokens. Each search token in the serialized request body will be replaced with its corresponding replace token before sending.

Parameters

ParameterTypeDescription
tokensMapMap of search tokens to their replacement values

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('PaymentGateway', '/charges')
   .body(chargeRequest)
   .replaceRequestTokens(new Map<String, String>{'currencyIsoCode' => 'currency', 'groupName' => 'group'})
   .send();

replaceResponseToken ​

apex
global UTIL_HttpClient.RequestBuilder replaceResponseToken(String searchToken, String replaceToken)

Registers a single response body replacement token. The search token in the response body will be replaced with the replace token after receiving.

Parameters

ParameterTypeDescription
searchTokenStringThe token to search for in the response body
replaceTokenStringThe token to replace it with

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
HttpResponse response = UTIL_HttpClient.get('PaymentGateway', '/charges')
   .replaceResponseToken('currency', 'currencyIsoCode')
   .send();

replaceResponseTokens ​

apex
global UTIL_HttpClient.RequestBuilder replaceResponseTokens(Map<String, String> tokens)

Registers multiple response body replacement tokens. Each search token in the response body will be replaced with its corresponding replace token after receiving.

Parameters

ParameterTypeDescription
tokensMapMap of search tokens to their replacement values

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
HttpResponse response = UTIL_HttpClient.get('PaymentGateway', '/charges')
   .replaceResponseTokens(new Map<String, String>{'currency' => 'currencyIsoCode', 'group' => 'groupName'})
   .send();

retryOn ​

apex
global UTIL_HttpClient.RequestBuilder retryOn(Set<Integer> statusCodes)

Chooses which HTTP status codes are worth another attempt. When the external system responds with one of the codes you list, the request is sent again straight away, in the same transaction, whatever its HTTP method: naming a code here is your choice to repeat the request. The same list decides whether a later retry is scheduled, which happens only when you also gave a wait time in withRetry, and a code you name is retried later too, whatever the method. A response with any other code is not retried, so an empty set retries nothing. Passing null is the same as not calling this method. Naming 500, 502 or 504 for a POST or PATCH without an idempotency key is at your own risk: the external system may have processed the request, and the call's issue, when one is logged, says so. If you do not call this method, the request is sent again straight away after a 408 or 503, and after a 500, 502 or 504 when it is safe to repeat; a POST or PATCH without an idempotency key is not sent again after a 500, 502 or 504, because the external system may have processed it. 425 and 429 mean "slow down", so the request waits for the scheduled retry instead.

Parameters

ParameterTypeDescription
statusCodesSetThe HTTP status codes that should be tried again

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withRetry(3)
   .retryOn(new Set<Integer>{500, 503})
   .send();

send ​

apex
global HttpResponse send()

Executes the HTTP request and returns the raw HttpResponse. A response always comes back, so a caller never has to guard the return. When the request produced no response of its own, because processing failed, the configuration refused the call or the circuit was open, the response you get has status code 0, which no HTTP exchange can report, and a status line holding the first error recorded for the call. Its body is unset. Repeat calls hand back the same response object as the first call. Every failure the framework handles for a call leaves this method answering with its response rather than throwing: a call refused before it leaves the org, a transport failure, an exception in the handler, a call record that cannot be saved, a stored logger context that cannot be read, and a masking rule that blocks the failure attachments. A try/catch around this call has nothing to catch on those paths. A governor limit is the platform's own exception, outside this contract, and no Apex code can catch it.

Returns HttpResponse — The HttpResponse from the callout

Example

apex
HttpResponse response = UTIL_HttpClient.get('MyService', '/data').send();

skipLogging ​

apex
global UTIL_HttpClient.RequestBuilder skipLogging()

Skips ApiCall__c persistence for this request.

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.get('MyService', '/healthCheck')
   .skipLogging()
   .send();

timeout ​

apex
global UTIL_HttpClient.RequestBuilder timeout(Integer milliseconds)

Sets how long, in milliseconds, to wait for the external system to answer. Without this call, or with null, the framework's default of 120,000 milliseconds (two minutes) applies. On a request built with useHandler, the handler's own timeout applies instead.

Parameters

ParameterTypeDescription
millisecondsIntegerThe timeout value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.get('MyService', '/data')
   .timeout(30000)
   .send();

withCircuitBreaker ​

apex
global UTIL_HttpClient.RequestBuilder withCircuitBreaker()

Enables circuit breaker protection under the service's own breaker: the credential's breaker for a call built from a credential, the handler's breaker for a call made through useHandler(...). Every call to the same service shares that breaker, so once it opens after repeated failures, later calls are refused without being sent until it cools off. Calling it after withCircuitBreaker(String) drops the name given there.

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withCircuitBreaker()
   .send();
apex
global UTIL_HttpClient.RequestBuilder withCircuitBreaker(String circuitName)

Enables circuit breaker protection under a breaker you name. Calls that give the same name share one breaker whatever credential or handler they use, and calls that give different names keep separate breakers even on the same credential, so one failing endpoint does not stop calls to another. The name also applies to a call made through useHandler(...), and the retries the framework schedules for a call built from a credential keep it. When the breaker is open, the call is refused without being sent and its error line names the breaker.

Parameters

ParameterTypeDescription
circuitNameStringThe name of the circuit breaker this call uses

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withCircuitBreaker('payment-gateway')
   .send();

withCorrelationId ​

apex
global UTIL_HttpClient.RequestBuilder withCorrelationId(String correlationId)

Keeps a correlation id with the call. The call record stores your transaction's logger context, including this id, so when the stored call runs again later (a scheduled retry) that run's log entries carry your transaction as their parent and keep your global context. The entries of an outbound call always correlate by the call's own trace id.

Parameters

ParameterTypeDescription
correlationIdStringThe correlation identifier

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withCorrelationId('txn-12345')
   .send();

withExponentialBackoff ​

apex
global UTIL_HttpClient.RequestBuilder withExponentialBackoff(Integer maxRetries, Integer baseBackoffSeconds)

Retries a failed request, and makes each scheduled retry wait twice as long as the one before.

Retries in the same transaction are sent again at once, because Apex cannot wait. A retry that is scheduled for later waits the base backoff the first time, then twice as long each time after that, up to 300 seconds. For a base of 2 seconds the waits are 2, 4, 8, 16 seconds and so on.

Every retry already made counts towards the doubling, including the ones sent again at once in the transaction. So a retry scheduled after three re-sends in the transaction waits 16 seconds. The count adds up across runs, and the call never makes more retries in total than maxRetries. When you also call withCircuitBreaker and the circuit is open, the wait is at least the circuit's time-out.

Through useHandler, your handler gets the same waits and the same maximum you pass here, on every run, unless it overrides createRetryStrategy; then its own strategy decides. A scheduled retry runs from the handler class alone, so it needs an API Setting record for the handler, with its API Credential and Endpoint Path filled in: the retry takes its credential and path from that record, not from the request. Without the record, the first run sends the request, but the retry it schedules ends Aborted instead of being sent. withRetry keeps the default waits: the base, then the base times the number of retries already made.

Parameters

ParameterTypeDescription
maxRetriesIntegerThe maximum number of retry attempts
baseBackoffSecondsIntegerThe base backoff period in seconds

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withExponentialBackoff(3, 2)
   .send();

withIdempotencyKey ​

apex
global UTIL_HttpClient.RequestBuilder withIdempotencyKey(String idempotencyKey)

Sets an explicit idempotency key for duplicate detection. When set, this key takes priority over auto-generated keys. It is sent as the Idempotency-Key header and recorded on the call, on send() and on a useHandler(...).invoke() alike, whether or not the service setting has Idempotency Enabled, and a POST or PATCH that carries it counts as safe to send again.

Parameters

ParameterTypeDescription
idempotencyKeyStringThe idempotency key value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('PaymentGateway', '/charges')
   .body(chargeRequest)
   .withIdempotencyKey('order-12345')
   .send();

withMockResponse ​

apex
global UTIL_HttpClient.RequestBuilder withMockResponse(API_MockFactory.MockResponse mockResponse)

Sets a mock response to inject at framework level, overriding the handler's own mock.

Parameters

ParameterTypeDescription
mockResponseAPI_MockFactory.MockResponseThe mock response to inject

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
API_MockFactory.MockResponse mock = new API_MockFactory.MockResponse();
mock.body = '{"id": "12345"}';
UTIL_HttpClient.post('MyService', '/send')
   .withMockResponse(mock)
   .send();

withParameter ​

apex
global UTIL_HttpClient.RequestBuilder withParameter(String name, String value)

Adds a request parameter for delegation mode, where your own handler class sends the request.

Parameters

ParameterTypeDescription
nameStringThe parameter name
valueStringThe parameter value

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.useHandler(API_SendEmail.class)
   .withParameter(API_SendEmail.PARAM_SUBJECT, 'Hello')
   .invoke();

withParameters ​

apex
global UTIL_HttpClient.RequestBuilder withParameters(Map<String, String> parameters)

Adds multiple request parameters for delegation mode, where your own handler class sends the request.

Parameters

ParameterTypeDescription
parametersMapMap of parameter names to values

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
Map<String, String> parameters = new Map<String, String>{'key' => 'value'};
UTIL_HttpClient.useHandler(API_SendEmail.class)
   .withParameters(parameters)
   .invoke();

withRetry ​

apex
global UTIL_HttpClient.RequestBuilder withRetry(Integer maxRetries)

Enables synchronous retry with the specified maximum attempts. After a 408 or 503 the request is sent again straight away, in the same transaction. After a 500, 502 or 504 it is sent again straight away only when it is safe to repeat: a GET, PUT or DELETE, or a request you gave an idempotency key with withIdempotencyKey. A POST or PATCH without a key is not sent again after those three, because the external system may have processed it; the call ends Failed with a line that says so. A 425 or 429 means "slow down", so it is not sent again straight away. To choose the codes yourself, use retryOn: a status you name there is sent again whatever the method, a POST or PATCH without a key included, so name a 500, 502 or 504 only when sending the request twice is safe.

Parameters

ParameterTypeDescription
maxRetriesIntegerThe maximum number of retry attempts

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withRetry(3)
   .send();
apex
global UTIL_HttpClient.RequestBuilder withRetry(Integer maxRetries, Integer backoffSeconds)

Enables synchronous retry with a linear backoff. The wait time lets the framework schedule a later retry when the attempts made straight away do not succeed. After a 408 or 503 the request is sent again straight away, in the same transaction. After a 500, 502 or 504 it is sent again, straight away or later, only when it is safe to repeat: a GET, PUT or DELETE, or a request you gave an idempotency key with withIdempotencyKey. A POST or PATCH without a key is not sent again after those three, because the external system may have processed it; the call ends Failed with a line that says so. A 425 or 429 means "slow down", so it waits for the later retry. To choose the codes yourself, use retryOn: a status you name there is sent again whatever the method, a POST or PATCH without a key included, so name a 500, 502 or 504 only when sending the request twice is safe.

Through useHandler, your handler gets the same waits and the same maximum you pass here, on every run, unless it overrides createRetryStrategy; then its own strategy decides. A scheduled retry runs from the handler class alone, so it needs an API Setting record for the handler, with its API Credential and Endpoint Path filled in: the retry takes its credential and path from that record, not from the request. Without the record, the first run sends the request, but the retry it schedules ends Aborted instead of being sent.

Parameters

ParameterTypeDescription
maxRetriesIntegerThe maximum number of retry attempts
backoffSecondsIntegerThe backoff period in seconds

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withRetry(3, 5)
   .send();

withTriggeringRecord ​

apex
global UTIL_HttpClient.RequestBuilder withTriggeringRecord(Id recordId)

Links this callout to a triggering business record.

Parameters

ParameterTypeDescription
recordIdIdThe Salesforce record Id

Returns UTIL_HttpClient.RequestBuilder — This builder for method chaining

Example

apex
UTIL_HttpClient.post('MyService', '/send')
   .withTriggeringRecord(record.Id)
   .send();