You need to sign in to do that
Don't have an account?

trigger to execute on case status = 'Escalated'
I can't seem to update my trigger so that it only creates a ticket in Jira (webservice connector) when the case status equals "Escalated". Can someone help?
trigger SynchronizeWithJIRAIssue on Case (after insert) {
system.debug('trigger!');
//Identify profile name to be blocked from executing this trigger
String JIRAAgentProfileName = 'JIRA Agent2';
List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];
//Check if specified Profile Name exist or not
if(!p.isEmpty())
{
//Check if current user's profile is catergorized in the blocked profile
if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
{
for (Case c : Trigger.new) {
system.debug('inside case ' + c.CaseNumber);
//Define parameters to be used in calling Apex Class
String jiraURL = 'http://xxxxxxx';
String systemId = '2';
String objectType ='Case';
String objectId = c.id;
String projectKey = 'xxx';
String issueType = 'xx';
System.debug('\n\n status is escalated');
//Execute the trigger
JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
}
}
}
}
trigger SynchronizeWithJIRAIssue on Case (after insert) {
system.debug('trigger!');
//Identify profile name to be blocked from executing this trigger
String JIRAAgentProfileName = 'JIRA Agent2';
List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];
//Check if specified Profile Name exist or not
if(!p.isEmpty())
{
//Check if current user's profile is catergorized in the blocked profile
if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
{
for (Case c : Trigger.new) {
system.debug('inside case ' + c.CaseNumber);
//Define parameters to be used in calling Apex Class
String jiraURL = 'http://xxxxxxx';
String systemId = '2';
String objectType ='Case';
String objectId = c.id;
String projectKey = 'xxx';
String issueType = 'xx';
System.debug('\n\n status is escalated');
//Execute the trigger
JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
}
}
}
}
I do have a class created, then have it reach out to the trigger. I originally had the "escalated' validtion in there, but removed it because it's wasn't working. Here is the class/callout:
global class JIRAConnectorWebserviceCallout {
@future (callout=true)
WebService static void createIssue( String jiraURL, String systemId, String objectType, String objectId, String projectKey, String issueType) {
System.debug('creating issue for ' + jiraURL);
//Set your username and password here
String username = 'xxxxx';
String password = 'xxxxxxx';
//Construct HTTP request and response
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();
//Construct Authorization and Content header
Blob headerValue = Blob.valueOf(username+':'+password);
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader);
req.setHeader('Content-Type','application/json');
req.setHeader('Content-Length','0');
req.setHeader('Project','xxx');
req.setHeader('Summary','xxx');
req.setHeader('Reporter','xxx');
req.setTimeout(30000);
//Construct Endpoint
//String endpoint = 'http://jira.xxxxxxxxx.com/plugins/servlet/customware/connector/issue/2/Case/create.action?id=' + objectId +
// '&Project=LEV&Reporter=xxxxxxxxx&Summary=test&issueType=27';
String endpoint = 'http://jira.optionscity.com/rest/customware/connector/1.0/2/Case/' + objectId + '/issue/create.json';
String data = '{"project":"LEV","issueType":"27"}';
system.debug('url is, ' + endpoint);
system.debug('data is, ' + data);
//Set Method and Endpoint and Body
req.setMethod('POST');
req.setEndpoint(endpoint);
req.setBody(data);
try {
//Send endpoint to JIRA
res = http.send(req);
} catch(System.CalloutException e) {
System.debug(res.toString());
System.debug('Callout error: '+ e);
System.debug(res.toString());
}
}
}