0

Salesforce IB Case Create/Update - Apex Trigger and Class

Context
This Apex code is used for Salesforce to fire an event into the xMatters Integrations builder. The code below fires after a Case record is inserted.

Usage
This would be added to a trigger on the Case table to fire after insert

Code


trigger xMattersAlert on Case (after insert) {
String endpoint = 'https://acme.dc.xmatters.com/api/integration/1/functions/UUID/triggers';
String caseid = '"Case ID":' + '"' + Trigger.New[0].CaseNumber + '"';
string description = '"Description":' + '"' + Trigger.New[0].Description + '"';
string priority = '"Priority":' + '"' + Trigger.New[0].Priority + '"';
string status = '"Status":' + '"' + Trigger.New[0].Status + '"';
string accountid = Trigger.New[0].AccountID;
string accountidj = '"Account ID":' + '"' + Trigger.New[0].AccountID + '"';
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( accountid );
System.Debug( payload );

xmattersreq.xRESTCall(endpoint, payload);
}



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());
}
}

0 comments

Please sign in to leave a comment.