Salesforce Integration
Integrate Salesforce events with ilert to notify teams of key activities or failures, ensuring critical alerts reach responders quickly.
Last updated
Was this helpful?
Was this helpful?
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+'"';
}
}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);
}