Product Communications
Context
RemedyForce is an app built on the Salesforce platform. The code below can be used to fire an event to xMatters.
Usage
This code would be added to a Trigger to fire after insert
Code
Salesforce Class record
The class record abstracts the code for making the HTTP call.
global class xMattersreq {
@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' );
Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(' Response: ' + res.getBody());
}
}
Trigger record on BMCServiceDesk_Incident_c table to fire after inserted uses the xMattersreq class created above to make the HTTP call to the xMatters POST /trigger endpoint.
trigger xMattersAlert on BMCServiceDesk_Incidentc (after insert) {
string endpoint = 'https://instance.d.xmatters.com/api/integration/1/functions/UUID/triggers';
string incidentname = '"Incident Name":' + '"' + Trigger.New[0].Name + '"';
string caseid = '"Case ID":' + '"' + Trigger.New[0].Name + '"';
string description = '"Description":' + '"' + Trigger.New[0].BMCServiceDeskincidentDescriptionc + '"';
string priority = '"Priority":' + '"' + Trigger.New[0].BMCServiceDeskImpact_Idc + '"';
string status = '"Status":' + '"' + Trigger.New[0].BMCServiceDeskStatus_IDc + '"';
string accountid = Trigger.New[0].BMCServiceDeskFKAccountc;
string accountidj = '"Account ID":' + '"' + Trigger.New[0].BMCServiceDeskFKAccount_c + '"';
string recordid = '"ID":' + '"' + Trigger.New[0].Id + '"';
Account record = [Select Name From Account Where Id = :accountid]; string accountname = '"Account Name":' + '"' + record.Name + '"';
String payload = '{' + recordid + ',' + caseid + ',' + description + ',' + priority + ',' + accountname + ',' + accountidj + ',' + status + '}';
System.Debug( payload) ;
xmattersreq.xRESTCall( endpoint, payload );
}
0
Comments
Please sign in to leave a comment.