Advertisement
Guest User

Untitled

a guest
Jun 16th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. global class JIRAWebserviceCalloutSyncStatus {
  2. @future (callout=true)
  3. WebService static void syncstatus(String status, String jiraKey) {
  4. //Modify these variables:
  5. String username = 'salesforceconnector';
  6. String password = 'Kabbage123!';
  7. String jiraURL = 'https://platformsupport.kabbage.com';
  8. String transitionId;
  9.  
  10. //Map Salesforce Status to JIRA transition Id:
  11. if (status == 'Waiting on Risk') { // Salesforce.com Status
  12. transitionId = '181'; // JIRA transition ID
  13. } else if (status == 'Waiting on Customer') {
  14. transitionId = '21';
  15. } else if (status == 'Active') {
  16. transitionId = '161';
  17. }
  18.  
  19.  
  20. //Construct HTTP request and response
  21. HttpRequest req = new HttpRequest();
  22. HttpResponse res = new HttpResponse();
  23. Http http = new Http();
  24.  
  25. //Construct Authorization and Content header
  26. Blob headerValue = Blob.valueOf(username+':'+password);
  27. String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
  28. req.setHeader('Authorization', authorizationHeader);
  29. req.setHeader('Content-Type','application/json');
  30.  
  31. //Construct Endpoint
  32. String endpoint = jiraURL+'/rest/api/2/issue/'+jiraKey+'/transitions';
  33.  
  34. //Set Method and Endpoint and Body
  35. req.setMethod('POST');
  36. req.setEndpoint(endpoint);
  37. req.setBody('{ "transition": {"id": "'+transitionId+'"}}');
  38.  
  39. try {
  40. //Send endpoint to JIRA
  41. res = http.send(req);
  42. } catch(System.CalloutException e) {
  43. System.debug(res.toString());
  44. }
  45. }
  46.  
  47. trigger SyncStatus on Case (after update) {
  48. //Identify profile name to be blocked from executing this trigger
  49. String JIRAAgentProfileName = 'JIRA Agent';
  50. List<Profile> p = [SELECT Id FROM Profile WHERE Name=:JIRAAgentProfileName];
  51.  
  52. //Check if specified Profile Name exist or not
  53. if(!p.isEmpty())
  54. {
  55. //Check if current user's profile is catergorized in the blocked profile
  56. if(UserInfo.getProfileId()!= String.valueOf(p[0].id))
  57. {
  58. for (Case c : Trigger.new) {
  59. //Define parameters to be used in calling Apex Class
  60. String status = c.Status;
  61. String jiraKey = c.JIRA_Key__c;
  62.  
  63. JIRAWebserviceCalloutSyncStatus.syncstatus(status, jiraKey);
  64. }
  65. }
  66. }
  67.  
  68. @isTest
  69. public class TestJIRAWebserviceCalloutSyncStatus {
  70.  
  71. static testMethod void TestJIRAWebserviceCalloutSyncStatus(){
  72. Test.startTest();
  73. JIRAWebserviceCalloutSyncStatus.syncstatus();
  74. Test.stopTest();
  75.  
  76.  
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement