Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class JIRAWebserviceCalloutSyncStatus {
- @future (callout=true)
- WebService static void syncstatus(String status, String jiraKey) {
- //Modify these variables:
- String username = 'salesforceconnector';
- String password = 'Kabbage123!';
- String jiraURL = 'https://platformsupport.kabbage.com';
- String transitionId;
- //Map Salesforce Status to JIRA transition Id:
- if (status == 'Waiting on Risk') { // Salesforce.com Status
- transitionId = '181'; // JIRA transition ID
- } else if (status == 'Waiting on Customer') {
- transitionId = '21';
- } else if (status == 'Active') {
- transitionId = '161';
- }
- //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');
- //Construct Endpoint
- String endpoint = jiraURL+'/rest/api/2/issue/'+jiraKey+'/transitions';
- //Set Method and Endpoint and Body
- req.setMethod('POST');
- req.setEndpoint(endpoint);
- req.setBody('{ "transition": {"id": "'+transitionId+'"}}');
- try {
- //Send endpoint to JIRA
- res = http.send(req);
- } catch(System.CalloutException e) {
- System.debug(res.toString());
- }
- }
- trigger SyncStatus on Case (after update) {
- //Identify profile name to be blocked from executing this trigger
- String JIRAAgentProfileName = 'JIRA Agent';
- 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) {
- //Define parameters to be used in calling Apex Class
- String status = c.Status;
- String jiraKey = c.JIRA_Key__c;
- JIRAWebserviceCalloutSyncStatus.syncstatus(status, jiraKey);
- }
- }
- }
- @isTest
- public class TestJIRAWebserviceCalloutSyncStatus {
- static testMethod void TestJIRAWebserviceCalloutSyncStatus(){
- Test.startTest();
- JIRAWebserviceCalloutSyncStatus.syncstatus();
- Test.stopTest();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement