Apex Class
You can know more about Apex class here. To Create an Apex Class
Click on settings icon

Then click on Setup option from the dropdown

Search for Apex Classes option and click on it

Click on New button

Copy and paste the below code snippet. The code snippet checks the Salesforce data and if there is any change/update in the customer information then it updates to CustomFit
public class CustomFitWebHook {
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 instanceURL = JSON.serialize(URL.getOrgDomainUrl().toExternalForm());
String content = '{"new": ' + newObjects + ', "old": ' + oldObjects + ', "userId": ' + userId + ', "instanceURL": ' + instanceURL + '}';
return content;
}
@future(callout=true) public static void callout(String content) {
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://api.customfit.ai/v1/salesforce/webhooks');
req.setMethod('POST');
req.setHeader('Content-Type', 'application/json');
req.setBody(content);
h.send(req);
}
}
Click on Save button

Last updated
Was this helpful?