• Amul Baranwal 6
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
 When ever a case has ben created it should directly create an issue  in Jira(wrote a Trigger on case object whenever a case is identified it will fire by applying some condition) now its turn to attach a file or attachment into Jira from Salesforce, myself strucked ova here.



public SalesforcetoJira(){}
//Change values in this class according to you JIRA/Salesforce coordinates
public String baseUrl = '';   // Base URL of your JIRA instance
public String username = ''; // JIRA username
public String password = ''; // JIRA password // Constructs Basic Http Authentication header from provided credentials
public String authHeader(){ Blob headerValue = Blob.valueOf(username+':'+password); return 'Basic ' + EncodingUtil.base64Encode(headerValue);
}
public SalesforcetoJira(JiraUrl,String objectType,String projectKey,String issueType,string summary,string description)
{
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
//Set HTTPRequest header properties
req.setHeader('Accept', 'application/json');
req.setHeader('Content-Type','application/json');
Blob headerValue = Blob.valueOf(username+':'+password);
req.setHeader('Authorization','Basic '+ EncodingUtil.base64Encode(headerValue));
req.setEndpoint(baseUrl);
String CreateIssueJsonJIra= '{"fields": {"project":{"key": " "},"summary":" ","description":" " ,"issuetype":{"name": "Bug"}}} ';
String JSONData = JSON.serializePretty(CreateIssueJsonJIra); r
eq.setBody(CreateIssueJsonJIra);
system.debug('after response....'+CreateIssueJsonJIra);
try{
//Execute web service call here
HTTPResponse res = http.send(req);
String ResponseJsonString = res.getBody();
map<string,string> attachment= (map<string,string>)JSON.deserializeUntyped(ResponseJsonStringJIra);
system.debug('after response...'+attachment);
system.debug('after response...'+attachment.get('id'));
System.debug('ResponseJsonStringJIra'+ResponseJsonStringJIra);
JSONParser parser = JSON.createParser(ResponseJsonStringJIra);
}
}
catch(System.CalloutException e)
{
System.debug('Callout error: '+ e);
}
}


I appreciate any help.