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

# Salesforce Integration

Integrate Salesforce events with ilert to notify teams of key activities or failures, ensuring critical alerts reach responders quickly.

By connecting [Salesforce](https://www.salesforce.com/) with ilert, technical signals are sent to on-call teams immediately. This allows rapid investigation of disruptions in CRM processes or data flows, ensuring fast mitigation.

## In ilert: Create a Salesforce alert source

1. Go to **Alerting** → **Alert sources** and click **Create new alert source**.
2. Search for **Salesforce**, click its tile, and click **Next**.
3. Give your alert source a name, optionally assign teams, and click **Next**.
4. Choose who gets notified: select **Use existing escalation policy** and pick a policy, or **Generate new escalation policy** to start with a basic one that notifies you first. Click **Next**.

   <figure><img src="https://3394882078-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M76ygPnS4HUcFSX8ulm%2Fuploads%2Fgit-blob-8a281bf3931f5a1a531951ce97984d50989dd875%2Falert-source-escalation-step.png?alt=media" alt="The escalation step of the ilert alert source wizard, headed Who should be notified about alerts, with an escalation policy selected and a preview of its escalation rules below."><figcaption><p>Pick an existing escalation policy, or generate a basic one without leaving the wizard.</p></figcaption></figure>
5. Select **Default grouping** and click **Continue setup**. It groups events by the alert key the integration sets; the other [grouping options](/alerting/configure-alerting/alert-sources.md#event-grouping) are easier to judge once events are arriving.
6. The next page shows more settings, such as notification priority and alert templates. Click **Finish setup** for now; you can change them later.
7. On the final page, ilert shows the integration key and URL for this alert source. You will need them later in this guide.

## In Salesforce

*This Documentation is based on the new Salesforce Lightning, new UI from Salesforce*

Navigate to Developer Console by clicking the **Settings** icon and then click the **Developer Console**.

![](https://3394882078-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M76ygPnS4HUcFSX8ulm%2F-MlHUsExMlg6RPiY_9_H%2F-MlHccYY1__ppb9Q83nS%2Fsalesforce-newmenu.png?alt=media\&token=04edc3cf-2c14-4763-87a3-6b5f7d185847)

In Developer Console page select **File** -> **New** -> **Apex Class** and copy the following and save it as **`ilertClass.apxc`**, then click Save.

```java
global class ilertClass {

    @future(callout=true)
    WebService static void xRESTCall(String endpoint, String payload){
        HttpRequest req = new HttpRequest();
        req.setEndpoint(endpoint);
        req.setMethod('POST');
        req.setBody(payload);
        req.setHeader( 'Content-Type', 'application/json' );
        req.setHeader( 'Accept', 'application/json' );
        Http http = new Http();
        HTTPResponse res = http.send(req);
        System.debug(' Response: ' + res.getBody());
    }

    global static string getPayloadStringByHandlingNull(String value){
        return value==null?null:'"'+value.replaceAll('[^a-zA-Z0-9\\s]', '').replaceAll('\\s+', ' ')+'"';
    }

    global static string getPayloadStringByHandlingNull(DateTime value){
        return value==null?null:'"'+value+'"';
    }

    global static string getPayloadStringByHandlingNull(Decimal value){
        return value==null?null:'"'+value+'"';
    }

    global static string getPayloadStringByHandlingNull(Boolean value){
        return value==null?null:'"'+value+'"';
    }
  }
```

Create a trigger by clicking **File** -> **New** -> **Apex Trigger** and copy the following and save it as **`ilertTrigger.apxt`**. Please make sure that the `API_KEY` and the `URL` is replaced based on the relevant `API_KEY` and `URL` that were received from ilert side.

```java
trigger ilertCaseTrigger on Case (after insert, after update) {
    
    string endpoint = 'URL';
    string apiKey = 'API_KEY';
    Case obj = Trigger.new[0];
    
    System.debug('ilertCaseTrigger Fired');

    string caseNumber = obj.CaseNumber;
    string subject = obj.Subject;
    string description = obj.Description;
    
    string eventType = 'ALERT';

    if (obj.IsClosed) {
        eventType = 'RESOLVE';
    }

   string payload= '{'+       
        '\"eventType\" :' + ilertClass.getPayloadStringByHandlingNull(eventType)+ ',' +
        '\"apiKey\" :' + ilertClass.getPayloadStringByHandlingNull(apiKey)+ ',' +
        '\"incidentKey\" :' + ilertClass.getPayloadStringByHandlingNull(caseNumber)+ ',' +
        '\"summary\" :' + ilertClass.getPayloadStringByHandlingNull(subject)+ ',' +
        '\"details\" :' + ilertClass.getPayloadStringByHandlingNull(description) +
    '}';
    
    System.debug('Payload: ' + payload);

    ilertClass.xRESTCall(endpoint, payload);
}
```

In order to send to ilert, the domain needs to be allowlisted, back to the Salesforce page and select Setup from settings and go to **Setup** -> **Security** -> **Remote Site** Settings page.

![](https://3394882078-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M76ygPnS4HUcFSX8ulm%2F-MlHUsExMlg6RPiY_9_H%2F-MlHdlfigOTkasFtuons%2Fsalesforce-remote.png?alt=media\&token=3cb788ab-fe7c-44ce-b0b8-3620022b7e95)

Add a new remote site name it "iLert" and then paste the URL copied **`https://api.ilert.com`** to the "Remote Site URL" field and Save.

To test this, simply create a **Case** in Salesforce.

## FAQ

1. How to Debug in case something is not working?\
   \
   In order to Debug this, you need to add `System.debug()` either on the trigger or the class. To view this just navigate to **Gear Icon -> Setup -> Environment -> Logs -> Debug Logs**\\
2. I don't see my logs, why?\
   \
   Make sure that the **Expiration Date** settings in the Debug Logs settings are set in the future, just edit it if it was done in the past, and create Case again.

![](https://3394882078-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M76ygPnS4HUcFSX8ulm%2F-MlHUsExMlg6RPiY_9_H%2F-MlHfUuVReD3_3hXampO%2Fsalesforce-debuglogs.png?alt=media\&token=5e600a0d-af4d-473a-ab17-df90da57a48a)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ilert.com/integrations/inbound-integrations/salesforce.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
