Step 2: Write Apex to Send an HTTP Call to the Connected App

After you configure the remote site, write the Apex code that sends an HTTP request to the connected app to initiate the content sync. To allow the panel components to trigger the Apex methods, use the @AuraEnabled annotation for each method.

The endpoint must match the URL entered in the Remote Site URL field.

Important

This Apex sample includes methods for calls to Heroku and Marketing Cloud.

1public with sharing class CmsControlPanelController {
2    @AuraEnabled
3    public static String rebuildHeroku() {
4        // Instantiate a new http object
5        Http h = new Http();
6
7        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
8        HttpRequest req = new HttpRequest();
9        req.setEndpoint('https://salesforcecms.herokuapp.com/build/');
10        req.setMethod('POST');
11
12        // Send the request, and return a response
13        HttpResponse res = h.send(req);
14        return res.getBody();
15    }
16    @AuraEnabled
17    public static String refreshMarketingCloud() {
18        // Instantiate a new http object
19        Http h = new Http();
20
21        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
22        HttpRequest req = new HttpRequest();
23        req.setEndpoint('https://salesforcecms.herokuapp.com/refreshMarketingCloud/');
24        req.setMethod('POST');
25
26        // Send the request, and return a response
27        HttpResponse res = h.send(req);
28        return res.getBody();
29    }
30}

See Also