# Apex Class

You can know more about Apex class [here](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dev_guide.htm). To Create an Apex Class

* Click on settings icon

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXYiUS3zpuXslGzfTpO%2F-MXYie9g0exx2OM2U_Jc%2Fimage.png?alt=media\&token=3bb0375a-d9cb-4c1c-875c-b421d88234bc)

* Then click on Setup option from the dropdown

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXYj-q-ecGbiA5BwVYw%2F-MXYj0n9LyhiRAM_Qxns%2Fimage.png?alt=media\&token=0bd80751-1c9d-4a55-8b98-2a05a03dbcc1)

* Search for Apex Classes option and click on it

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXXdpeGqOHHnknEZNO8%2F-MXXfqhyorewCdeU82VB%2Fimage.png?alt=media\&token=f5605c6a-e848-4d3b-8753-0abcb8397aa6)

* Click on New button

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXYj-q-ecGbiA5BwVYw%2F-MXYjUnecx65udp3Uzm8%2Fimage.png?alt=media\&token=d3f1df98-f1d4-45bc-b188-ded8368f60fb)

* 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

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXYj-q-ecGbiA5BwVYw%2F-MXYk2mqj5rtSUwrbbwh%2Fimage.png?alt=media\&token=bee8c455-a967-4b13-aa86-5b7e8ab3ef27)
