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
Implementation
- The
CalloutManagerclass is the core of this submodule, implementing a fluent API to easily build and send requests - Configurations can be stored using the
Callout_Configuration__mdtCustom 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__cCustom 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
HttpRequestclass doesn't provide, such as addingURL Params - Generate structured logs of HTTP Callout request and response data
