Skip to content

Callout

The Callout submodule provides functionality to streamline how HTTP requests are made to external systems (i.e., outside of Salesforce). It provides a simple and efficient way to send HTTP requests and handle responses.

Documentation

💾 Source Code

Callout

Implementation

  • The CalloutManager class is the core of this submodule, implementing a fluent API to easily build and send requests
  • Configurations can be stored using the Callout_Configuration__mdt Custom Metadata Type, or by chaining the builder methods to specify desired options
  • Convenience methods, such as adding URL Params, have been added to make it even easier to build and send requests
  • When a request is sent, an instance of the Request__c Custom Object is generated that can be persisted to log request and response data

Demos

apex
// Build callout
CalloutManager callout = new CalloutManager();
callout.withCalloutName('MyCallout');
callout.withFullEndpoint('https://example.com/api');
callout.withHttpMethod('POST');
callout.withTimeout(5000);
callout.withCompression(false);
callout.withHeader('X-Test','value');
callout.withQueryParam('q','1');
callout.withBody('{"data":"x"}');

// Send request
CalloutManager.CalloutResult result = callout.send();
Database.insert(result.resultRecord, AccessLevel.USER_MODE);

Benefits

  • Auto-create callouts based on stored configurations
  • Leverage convenience methods that the native HttpRequest class doesn't provide, such as adding URL Params
  • Generate structured logs of HTTP Callout request and response data

SlightWork is part of the Wynforce ecosystem