> For the complete documentation index, see [llms.txt](https://doc.customfit.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.customfit.ai/integrations/salesforce/apex-triggers.md).

# Apex Triggers

**Apex triggers** enable you to perform custom actions before or after events to records in **Salesforce**, such as insertions, updates, or deletions.� You can know more about Apex triggers [here](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm). You need to create three different triggers

1. **Contact Trigger** - If there is any change to the Contact then contact trigger will be invoked
2. **Lead Trigger** - If there is any change to the Lead then lead trigger will be invoked
3. **Account Trigger** - If there is any change to the Account then account trigger will be invoked

To create a trigger follow the below steps

* Click on settings icon

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_ReqGLTOLuEcedcxq%2F-MX_RnlFgv1GEnxN4TpC%2Fimage.png?alt=media\&token=ef40b9c6-8203-468e-8b10-130a5deb7b82)

* Then click on Setup option from the dropdown

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_ReqGLTOLuEcedcxq%2F-MX_Rrt76Hq96EiiQE7o%2Fimage.png?alt=media\&token=daf7bb53-6285-433a-9c1e-4d8f69a388e7)

* Search for Apex Triggers option and click on it

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MXXdpeGqOHHnknEZNO8%2F-MXXg0NQ6JHQsqMXoZzG%2Fimage.png?alt=media\&token=a7242aba-6152-4e5a-897f-0d256f1e58d4)

* Click on Developer Console button

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_ReqGLTOLuEcedcxq%2F-MX_SRSXOTn9J3PxdJJi%2Fimage.png?alt=media\&token=d8d46b97-8d72-4fb5-9114-8620ef9e7302)

* In the developer Console click on File
* Click on New and Select the Apex Trigger option

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_ReqGLTOLuEcedcxq%2F-MX_TIyNyVNH8VxFvB1L%2Fimage.png?alt=media\&token=2644d1c5-2e31-49e7-b372-f705cad7a204)

* For the Contact Trigger give the&#x20;

  * Name as ContactTrigger
  * For sObject select Contact from the dropdown

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_U376m9rwRi-R9yDx%2F-MX_a-v-z_ZJnB7_40LH%2Fimage.png?alt=media\&token=b0719b30-7dcd-44ab-9bee-1c9d5644e705)

* Then paste the below code

```
trigger ContactTrigger on Contact (after insert,after update,after delete) {
    CustomFitWebHook.callout(CustomFitWebHook.jsonContent(Trigger.new, Trigger.old));
}
```

* Atlast save the code
* For the Lead Trigger give the&#x20;

  * Name as LeadTrigger
  * For sObject select Lead from the dropdown

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_a4R0Zzn9JU6JdpcZ%2F-MX_cOITJVJWMrZ8XWRt%2Fimage.png?alt=media\&token=deae47a2-d199-466d-b18b-213a20b075fc)

* Then paste the below code

```
trigger LeadTrigger on Lead (after insert,after update,after delete) {
    CustomFitWebHook.callout(CustomFitWebHook.jsonContent(Trigger.new, Trigger.old));
}

```

* Atlast save the code
* For the Account Trigger give the&#x20;

  * Name as AccountTrigger
  * For sObject select Account from the dropdown

![](https://1136256215-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MUgAFLO61VraHX8jwLt%2F-MX_a4R0Zzn9JU6JdpcZ%2F-MX_crFga9zhUrTNbS0J%2Fimage.png?alt=media\&token=e714f87b-9ccd-4be2-a8b6-c43d581ee19c)

* Then paste the below code

```
trigger AccountTrigger on Account (after insert,after update,after delete) {
    CustomFitWebHook.callout(CustomFitWebHook.jsonContent(Trigger.new, Trigger.old));
}

```

* Atlast save the code
