A configurable API Callout Framework

Callout Config (Beta)

The Callout Config is a framework concept to optimize all apex callouts within an organization. Its goals are to minimize the overall code needed for callouts, eliminate code redundancy, and enhance both maintainability and scalability.

It's intended to complement Named Credentials and doesn't propose any alternatives to the features provided by Named Credentials. Named credentials can further be configured in to this framework to make things more configurable and secure. This allows to securely configure parameters to Endopint, header and body beyond what is configured in Named Credentails.


CalloutService - this class is where we request is created, callout is made, resopse is captured. This is where all the parsing methods will be added which can be used by all callouts. This is not dependent on the other class and can be used directly without using the CalloutConfigService class

CalloutConfigService - this class creats CalloutService from the configurations created. this can handle Named Credentails cnfigured in to the configuration objects

OBJECTS: Note: Custom Metadata Types can also be used instead of Custom Objects, but using Custom Objects allows to configure secure data as well (As of today encripted fields are not supported in Custom Metadata Types)

1. Api__c - Coming soon...

2. Parameter__c - Coming soon...

Usage/Examples With Named Credentials

Bitly token External Credentail


Bitly token Named Credentail


Bitly token configured with the Named Credentail


Bitly token body configired as a parameter with Named Credentail merge fields


Bitly url shorten endpoint configured directly in to API object and its two header parameters configured as related Parameters


Sample Code

String long_url = 'https://www.sfdcbox.com/2022/11/looping-of-asynchronousapex-calls-from.html';
// To make call for getting access token
String token = CalloutConfigService.newInstance('Bitly Token').makeCall().getResponse().getBody();
// To make call for getting shortened url for a long url
ICalloutService service = CalloutConfigService.newInstance('Bitly Shorten')
                                                .setAuthorization('Bearer '+token)
                                                .setJsonBodyParameter('long_url', long_url)
if(service.getResponse().getStatusCode() == 200){

18:07:19.99 (966585749)|USER_DEBUG|[10]|DEBUG|https://bit.ly/4c3jL1X

Usage/Examples Without Named Credentials

image image

To directly fetch a value from response

String type = CalloutConfigService.newInstance()
                        .setApiName('Geocoding API')
                        .setEndpointParameter('q', 'illinois')

To validate response and read response values

ICalloutService service = CalloutConfigService.newInstance()
                        .setApiName('Geocoding API')
                        .setEndpointParameter('q', 'illinois')
if(service.getResponse().getStatusCode() == 200){
    //Handle failure


Popular Posts