AlertOps and Salesforce
AlertOps’ alert management system can be integrated with Salesforce Service Cloud (Case Management) to receive and respond to all (predefined status mappings) case alerts through email, SMS, push notification or phone alerts. AlertOps would ensure that the alert/case status would reach the appropriate team by using proper workflows, escalation policies and schedules. Based on your ruleset, incidents can be automatically opened and closed, depending on whether Salesforce reports an opening, update or close of a case.
The above scenario and scope for integration is due to the fact that AlertOps has a very flexible and simple API/Webhook configuration feature that can be leveraged with Salesforce's remote trigger capabilities.
AlertOps - Inbound Integration
We can define some rulesets in AlertOps so that Salesforce can send out case alerts to the AlertOps platform. AlertOps would ensure based on these notifications received, that it would always reach out and assign to the correct person/team by utilizing its escalation policies, schedules, and workflow features.
AlertOps provides Inbound Integrations to integrate with numerous monitoring, chat and ITSM tools. You can configure an inbound integration for Salesforce Case Management Alerts.
At a high level this is how the flow looks like, you define an API integration in the AlertOps platform by defining settings like Integration Name, Escalation rules, recipient users/groups. Once an integration is defined, a unique API URL is generated. This acts as webhook or the gateway through which notifications from Salesforce reach AlertOps and thus an incident/alert is created correspondingly. The API can be defined with various settings like URL mappings, filters, escalations etc. as required. Salesforce has to be defined with an Apex Class and Apex Trigger to send out case alerts.
To configure an Inbound Integration in AlertOps to receive alerts from Salesforce,
Under 'Integrations' select 'Inbound Integrations', select the category 'API' and then select add 'Add API Integration'
There are numerous integration options available in AlertOps, select Salesforce Case Management/Salesforce (else select Custom)
Once you select the integration, you can then specify basic settings like the integration name, escalation policy, names of the recipients/groups for which the alerts must be assigned to.
Once you click save, the API Integration will be created, and you will be given a unique URL which acts as the access point and needs to be configured at the source (in this case Salesforce), to send alerts. You can find the integration you just created, and you can give advanced settings and define various configurations for the alerts to be received and processed. For example, you can define when to open and close alerts based on the payload obtained from the API call, filters etc.
Make a note of the API URL, which will be used in Salesforce Apex Class/Trigger, so it calls a HTTP POST request to this URL with the body in JSON format containing the alert specific information. AlertOps automatically creates an alert when the status variable (status) contains 'New' or 'Working'. The incident will also be closed automatically when the status 'Closed' is received from Salesforce. (and updated when 'Escalated' is received)
You can similarly define URL mappings as you want, owing to the flexibility provided by AlertOps’ OpenAPI/Plug-and-Play integrations. You can provide other filters and match with regex expressions as well. You can also test the generated URL.
Configuration of Salesforce for the Integration,
In your Salesforce Cloud/Developer instance portal, select the settings icon in the top right corner and select 'Developer Console'.
A new developer console window opens up. Go to 'File' -> 'New' -> select 'Apex Class'. Give the name 'alertopsIntegrationCall' and paste the following,
global class alertopsIntegrationCall {
@future(callout=true)
// OUTBOUND HTTP POST REQUEST METHOD
webservice static void outboundCallToAO(String endpoint, String payload){
HttpRequest req = new HttpRequest();
req.setEndpoint(endpoint);
req.setMethod('POST');
req.setBody(payload);
req.setHeader( 'Content-Type', 'application/json' );
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(' Response: ' + res.getBody());
}
// GLOBAL METHODS TO HANDLE NULL VALUES FOR DIFFERENT TYPES - EMPTY VALUES IN ALERTOPS WILL BE INGESTED AS null
global static string handleNull(String value){
return value==null?null:'"'+value.replaceAll('[^a-zA-Z0-9\\s]', '').replaceAll('\\s+', ' ')+'"';
}
global static string handleNull(DateTime value){
return value==null?null:'"'+value+'"';
}
global static string handleNull(Decimal value){
return value==null?null:'"'+value+'"';
}
global static string handleNull(Boolean value){
return value==null?null:'"'+value+'"';
}
}
Save it, again go to File -> "New" -> "Apex Trigger". Give the name "alertopsTriggerClass" and paste the following. In the 'endpoint' string replace it with your inbound integration API URL from AlertOps
trigger alertopsTriggerClass on Case (after insert, after update) {
// ENDPOINT - MAKE SURE YOU USE THE INBOUND INTEGRATION URL FROM ALERTOPS HERE
string endpoint = '<ALERTOPS API INBOUND URL>';
Case obj = Trigger.new[0];
//PAYLOAD FORMATTED, YOU CAN ADD/REMOVE/EDIT HOWEVER NEEDED, SPECIFICALLY HAS ALL VARIABLES, DO NOT REMOVE REQUIRED FIELDS
string id=obj.Id; //REQUIRED
string ownerId=obj.OwnerId; //REQUIRED
boolean isDeleted = obj.IsDeleted;
string caseNumber = obj.CaseNumber; //REQUIRED
string contactId = obj.ContactId;
string accountId = obj.AccountId;
string assetId = obj.AssetId;
string parentId = obj.ParentId;
string suppliedName = obj.SuppliedName;
string suppliedEmail = obj.SuppliedEmail;
string suppliedCompany = obj.SuppliedCompany;
string suppliedPhone = obj.SuppliedPhone;
string typeOfCase = obj.Type; //REQUIRED
string status = obj.Status; //REQUIRED
string reason = obj.Reason; //REQUIRED
string origin = obj.Origin;
string subject = obj.Subject; //REQUIRED
string description = obj.Description; //REQUIRED
boolean isClosed = obj.IsClosed;
string priority = obj.Priority; //REQUIRED
datetime closedDate = obj.ClosedDate;
boolean isEscalated = obj.IsEscalated;
boolean isClosedOnCreate = obj.IsClosedOnCreate;
datetime createdDate = obj.CreatedDate; //REQUIRED
string createdById = obj.CreatedById;
datetime lastModifiedDate = obj.LastModifiedDate;
string lastModifiedById = obj.LastModifiedById;
string contactPhone = obj.ContactPhone;
string contactMobile = obj.ContactMobile;
string contactFax = obj.ContactFax;
string engineeringReqNumber = obj.EngineeringReqNumber__c;
string product = obj.Product__c;
string potentialLiability = obj.PotentialLiability__c;
//FORMATING PAYLOAD TO A JSON FORMAT
string payload= '{'+
'\"id\" :' + alertopsIntegrationCall.handleNull(id)+ ',' +
'\"ownerId\" :' + alertopsIntegrationCall.handleNull(ownerId )+ ',' +
'\"isDeleted\" :' + alertopsIntegrationCall.handleNull(isDeleted)+ ',' +
'\"caseNumber\" :' + alertopsIntegrationCall.handleNull(caseNumber)+ ',' +
'\"contactId\" :' + alertopsIntegrationCall.handleNull(contactId)+ ',' +
'\"accountId\" :' + alertopsIntegrationCall.handleNull(accountId)+ ',' +
'\"assetId\" :' + alertopsIntegrationCall.handleNull(assetId)+ ',' +
'\"priority\" :' + alertopsIntegrationCall.handleNull(priority)+ ',' +
'\"parentId\" :' + alertopsIntegrationCall.handleNull(parentId)+ ',' +
'\"suppliedName\" :' + alertopsIntegrationCall.handleNull(suppliedName)+ ',' +
'\"suppliedEmail\" :' + alertopsIntegrationCall.handleNull(suppliedEmail)+ ',' +
'\"suppliedCompany\" :' + alertopsIntegrationCall.handleNull(suppliedCompany)+ ',' +
'\"suppliedPhone\" :' + alertopsIntegrationCall.handleNull(suppliedPhone)+ ',' +
'\"typeOfCase\" :' + alertopsIntegrationCall.handleNull(typeOfCase)+ ',' +
'\"status\" :' + alertopsIntegrationCall.handleNull(status)+ ',' +
'\"reason\" :' + alertopsIntegrationCall.handleNull(reason)+ ',' +
'\"origin\" :' + alertopsIntegrationCall.handleNull(origin)+ ',' +
'\"subject\" :' + alertopsIntegrationCall.handleNull(subject)+ ',' +
'\"description\" :' + alertopsIntegrationCall.handleNull(description)+ ',' +
'\"isClosed\" :' + alertopsIntegrationCall.handleNull(isClosed)+ ',' +
'\"closedDate\" :' + alertopsIntegrationCall.handleNull(closedDate)+ ',' +
'\"isEscalated\" :' + alertopsIntegrationCall.handleNull(isEscalated)+ ',' +
'\"isClosedOnCreate\" :' + alertopsIntegrationCall.handleNull(isClosedOnCreate)+ ',' +
'\"createdDate\" :' + alertopsIntegrationCall.handleNull(createdDate)+ ',' +
'\"createdById\" :' + alertopsIntegrationCall.handleNull(createdById)+ ',' +
'\"lastModifiedDate\" :' + alertopsIntegrationCall.handleNull(lastModifiedDate)+ ',' +
'\"contactPhone\" :' + alertopsIntegrationCall.handleNull(contactPhone) + ',' +
'\"contactMobile\" :' + alertopsIntegrationCall.handleNull(contactMobile)+ ',' +
'\"contactFax\" :' + alertopsIntegrationCall.handleNull(contactFax)+ ',' +
'\"engineeringReqNumber\" :' + alertopsIntegrationCall.handleNull(engineeringReqNumber)+ ',' +
'\"product\" :' + alertopsIntegrationCall.handleNull(product)+ ',' +
'\"potentialLiability\" :' + alertopsIntegrationCall.handleNull(potentialLiability)+
'}';
// CALL THE ALERTOPS INTEGRATION APEX CLASS FILE
alertopsIntegrationCall.outboundCallToAO(endpoint ,payload);
}
Save !
Now go to 'Settings' icon in your Salesforce Cloud Portal, select 'Setup'. Search for 'Support Settings'. You should have a checkbox that says 'Show Closed Statuses in Case Status Field'. Make sure it is checked. (This is for closing the case through the Status field, that would be the corresponding alert close condition in AlertOps)
Go to Setup -> Security -> Remote Site Settings. Make sure you add the AlertOps API endpoint URL (https://notify.alertops.com/) as a remote site.
Thats it! You have configured an integration, Apex Class, Apex Trigger. Any trigger event/status change event would now send an alert to AlertOps for incident management.
Message logs, alert specific information can be viewed in the “Inbound Log” section in AlertOps Dashboard. Alerts can be viewed in the ‘Alerts’ tab as well.
Alert Triggering Information:
AlertOps will automatically create an incident when a new alert is received from Salesforce when the status field contains "New" or "Working".
If an alert with status "New" or "Working" matches an existing Open Alert, AlertOps will recognize the new alert as a duplicate and ignore the alert.
The alert will be recorded in the Inbound Messages table as “Mapped Appended.”
AlertOps will automatically close the same incident when an alert with status contains 'Closed'