Add Webhook class to Salesforce account
- Log in into your Salesforce Account, navigate to the top right corner, select the Cog icon, and select Setup.
- Navigate to the left panel, scroll down and select Custom Code, and then Apex Classes
- Select New to create a new Apex Class.
- Name the class Webhook and paste the following code snippet:
public class Webhook implements HttpCalloutMock {
public static HttpRequest request;
public static HttpResponse response;
public HTTPResponse respond(HTTPRequest req) {
request = req;
response = new HttpResponse();
response.setStatusCode(200);
return response;
}
public static String jsonContent(List<Object> triggerNew, List<Object> triggerOld) {
String newObjects = '[]';
if (triggerNew != null) {
newObjects = JSON.serialize(triggerNew);
}
String oldObjects = '[]';
if (triggerOld != null) {
oldObjects = JSON.serialize(triggerOld);
}
String userId = JSON.serialize(UserInfo.getUserId());
String content = '{"new": ' + newObjects + ', "old": ' + oldObjects + ', "userId": ' + userId + '}';
return content;
}
@future(callout=true)
public static void callout(String url, String content) {
if (Test.isRunningTest()) {
Test.setMock(HttpCalloutMock.class, new Webhook());
}
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(url);
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(content);
h.send(req);
}
}
Add service domain
To add a service domain, go to your Cyclr console:
- Go to Settings > General Settings
- Copy your Service Domain.
- Login into your Salesforce Account, navigate to the top right corner and click the Clog icon, then click Setup.
- Navigate to the left panel, scroll down and click Security, then click Remote Site Settings
- Select New Remote Site, enter a name and add your Service Domain from step 2.