Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

Callouts for Salesforce Connect Custom Adapters

Just like any other Apex code, a Salesforce Connect custom adapter can make callouts. If the connection to the external system requires authentication, incorporate the authentication parameters into the callout.

Authentication parameters are encapsulated in a ConnectionParams object and provided to your DataSource.Connection class’s constructor.

For example, if your connection requires an OAuth access token, use code similar to the following.
1public HttpResponse getResponse(String url) {
2    Http httpProtocol = new Http();
3    HttpRequest request = new HttpRequest();
4    request.setEndPoint(url);
5    request.setMethod('GET');
6    request.setHeader('Authorization', 'Bearer ' + 
7            this.connectionInfo.oauthToken);
8    HttpResponse response = httpProtocol.send(request);
9    return response;
10}
If your connection requires basic password authentication, use code similar to the following.
1public HttpResponse getResponse(String url) {
2    Http httpProtocol = new Http();
3    HttpRequest request = new HttpRequest();
4    request.setEndPoint(url);
5    request.setMethod('GET');
6    string encodedHeaderValue = EncodingUtil.base64Encode(Blob.valueOf(
7            this.connectioninfo.username + ':' + 
8            this.connectionInfo.password));
9    request.setHeader('Authorization', 'Basic ' + encodedHeaderValue);
10    HttpResponse response = httpProtocol.send(request);
11    return response;
12}

Named Credentials as Callout Endpoints for Salesforce Connect Custom Adapters

A Salesforce Connect custom adapter obtains the relevant credentials that are stored in Salesforce whenever they’re needed. However, your Apex code must apply those credentials to all callouts, except those that specify named credentials as the callout endpoints. A named credential lets Salesforce handle the authentication logic for you so that your code doesn’t have to.

If all your custom adapter’s callouts use named credentials, you can set the external data source’s Authentication Protocol field to No Authentication. The named credentials add the appropriate certificates and can add standard authorization headers to the callouts. You also don’t need to define a remote site for an Apex callout endpoint that’s defined as a named credential.