1. Home
  2. Integrations
  3. Salesforce Integration Guide – VictorOps

Salesforce Integration Guide – VictorOps

This integration is for Salesforce service cloud users with access to the developer tools. The integration triggers an incident in VictorOps upon the creation of a case in Salesforce and then resolves it when the case is closed. The following is a step-by-step walkthrough of how to configure the integration.

Requirements

Versions Supported: SaaS product; for further reference please see Salesforce Editions documentation.

VictorOps Versions Required: VictorOps Standard or Enterprise

What you need to know: This integration is for Salesforce service cloud users with access to the developer tools. The integration triggers an incident in VictorOps upon the creation of a case in Salesforce and then resolves it when the case is closed. This VictorOps integration makes use of our REST API and requires that you’ve implemented Salesforce with your infrastructure.


Example Video


Configuration in VictorOps

In VictorOps please go to Settings -> Alert Behavior -> Integrations. Our integrations are arranged in alphabetical order.

Please scroll down and select the Salesforce icon from the list of available integrations.

Once selected, please Enable Integration.

From here you are able to copy the Service API Endpoint.


Configuration in Salesforce

In order to make a POST request to a remote site from Salesforce you need to add http://alert.victorops.com as a remote site under -> Security Controls -> Remote Site Settings -> New Remote Site


The Apex Code

There are five bits of Apex code utilized to accomplish this integration, all of which are contained in this GitHub Repository.

The VictorOpsTimeLine class contains the logic to both parse the JSON and make the HTTP POST request. There are also two triggers (one for CRITICAL alerts and one for RECOVERY), both require a test class in order to be pushed to production.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class VictorOpsTimeLine{
    public static boolean isApexTest = false;
    public static boolean caseIsClosed = true;
   @future(callout=true)
    public static void caseToVictor(boolean isRecovery, String casenumber, String subject, String name, String company,String description, String reason, String email){
       String AtMessage='from: ';
       String IssueMessage=', Case Subject: ';
       String critical='critical';
       String recovery='recovery';
       String message='New SalesForce Case '+AtMessage + ifnull(name,email) + IssueMessage + ifnull(reason,subject);
HttpRequest req = new HttpRequest();
Http http = new Http();
 
req.setEndpoint('http://alert.victorops.com/integrations/generic/20131114/alert/$YOUR_API_KEY_HERE/$ROUTING_KEY_HERE');
req.setMethod('POST');
Map<String, String> data = new Map<String, String>();
data.put('message_type', ifRecover(isRecovery, recovery,critical));
data.put('entity_id', casenumber);
data.put('entity_display_name', 'SalesForce Case Number: ' +casenumber);
data.put('monitoring_tool', 'SalesForce');
data.put('state_message', message);
data.put('Subject', subject);
data.put('Contact_Name ', name);
data.put('Company_Name', company);
data.put('Case_Desctiption', description);
data.put('Case_Reason', reason);
data.put('Contact_Email', email);
 
String body = JSON.serialize(data);
System.debug(body);
req.setBody(body);
req.setHeader('Content-Type','application/json');
 
// Create a new http object to send the request object
 
// A response object is generated as a result of the request
 
 
     if (!isApexTest){
HTTPResponse res = http.send(req);
System.debug(res.getBody());
} 
  }
 
 
 private static String ifnull(String maybeValue, String defaultValue) {
   if(maybeValue != null) {
     return maybeValue;
    } else {
      return defaultValue;
    }
 }
  private static String ifRecover(boolean isRecovery, String recovery, string critical){
    if (isRecovery){
       return recovery;
    } else {
       return critical;
    } 
  } 
}

 

Before adding the code to Salesforce you will need to grab your API_KEY and appropriate ROUTE_KEY to the POST request endpoint URL found in the VictorOpsTimeLine class on line 14. If you would like to add any custom fields to the code you will need to include it as an additional data.put in the VictorOpsTimeLine class and in all instances of VictorOpsTimeLine.caseToVictor which is in every class and trigger. For additional help see the video at the top of this page.

Once the code includes the API_KEY, ROUTE_KEY and any custom fields, you can either put all five parts of the code into a Salesforce Sandbox and deploy it as a ‘change set’ or use the Force IDE. More information regarding deploying Apex code to production can be found here.

 

Updated on July 19, 2017

Was this article helpful?

Related Articles