Hi Everyone,
We have a custom Object i.e., Jira Case on Salesforce side and in this object we have field called "Jira Description" this is type of Rich Text and the use case is whenever the support users add any screen-capture or images in this field or Modify the content having font size, Underlined content etc.,. This has to be shown in the Jira "Description" field using REST API. Basically we have to show the images and the same content from Salesforce Description field to JIRA Description field
We tried to do this but it shows the URL for the image in Salesforce and content with HTML tags.
Is there any way we can decode the "Jira Description" field from Salesforce to JIRA to copy the same information from Salesforce to JIRA by using REST API. Please suggest if any solution.
My findings: In JIRA Description field we can do content formatting and add the screen-captures as same as Rich Text field.
Below is the API we are using to POST from Salesforce
https://domain.atlassian.net/rest/api/2/issue
Below is the Trigger on Salesforce
Public class SalesforceToJiraCallouts {
public static void getJiraDetails(list<Jira_Case__c> jiraCaseRecordsList){
SalesforceToJiraCalloutsBugParser jsonParserForBug = new SalesforceToJiraCalloutsBugParser();
SalesforceToJiraCalloutsIssueParser jsonParserForEnhancement = new SalesforceToJiraCalloutsIssueParser();
for(Jira_Case__c jiraCaseRecord: jiraCaseRecordsList ){
if(jiraCaseRecord.Link_to_Existing_Jira__c == false){
string jiraCaseDescription = jiraCaseRecord.Jira_Description__c;
jiraCaseDescription = jiraCaseDescription;
if(jiraCaseRecord.Jira_Issue_Type__c == 'Enhancement'){
if(jiraCaseRecord.Product_Sub_Type__c == '3D Sprint' && jiraCaseRecord.Jira_Project_Name__c == '3D Sprint'){
jsonParserForEnhancement.Fields.project.key = system.Label.X3D_Sprint;
list<string> jiraAffectVersionsList = jiraCaseRecord.Jira_Affect_Versions__c.split(';');
system.debug('jiraAffectVersionsList' + jiraAffectVersionsList);
list<SalesforceToJiraCalloutsIssueParser.versions> versionList = new list<SalesforceToJiraCalloutsIssueParser.versions>();
if(jiraAffectVersionsList.size()>0){
for(integer i=0; i<jiraAffectVersionsList.size();i++){
SalesforceToJiraCalloutsIssueParser.versions version = new SalesforceToJiraCalloutsIssueParser.versions();
version.name = jiraAffectVersionsList[i];
versionList.add(version);
system.debug('jiraAffectVersionsList' + jiraAffectVersionsList[i]);
}
}
jsonParserForEnhancement.fields.versions = versionList;
}
else if(jiraCaseRecord.Product_Sub_Type__c == '3D Sprint' && jiraCaseRecord.Jira_Project_Name__c == 'SBU Licensing System'){
jsonParserForEnhancement.Fields.project.key = system.Label.SBU_Licensing_System;
}
jsonParserForEnhancement.fields.issuetype.name = 'Improvement';
jsonParserForEnhancement.fields.summary = jiraCaseRecord.Jira_Summary__c;
jsonParserForEnhancement.fields.description = jiraCaseDescription;
jsonParserForEnhancement.fields.customfield_10408 = jiraCaseRecord.Jira_Customer_Info__c;
jsonParserForEnhancement.fields.customfield_13961 = jiraCaseRecord.Name;
}
else{
if(jiraCaseRecord.Product_Sub_Type__c == '3D Sprint' && jiraCaseRecord.Jira_Project_Name__c == '3D Sprint'){
jsonParserForBug.Fields.project.key = system.Label.X3D_Sprint;
list<string> jiraAffectVersionsList = jiraCaseRecord.Jira_Affect_Versions__c.split(';');
list<SalesforceToJiraCalloutsBugParser.versions> versionList = new list<SalesforceToJiraCalloutsBugParser.versions>();
if(jiraAffectVersionsList.size()>0){
for(integer i=0; i<jiraAffectVersionsList.size();i++){
SalesforceToJiraCalloutsBugParser.versions version = new SalesforceToJiraCalloutsBugParser.versions();
version.name = jiraAffectVersionsList[i];
versionList.add(version);
system.debug('jiraAffectVersionsList' + jiraAffectVersionsList[i]);
}
}
jsonParserForBug.fields.versions = versionList;
}
else if(jiraCaseRecord.Product_Sub_Type__c == '3D Sprint' && jiraCaseRecord.Jira_Project_Name__c == 'SBU Licensing System'){
jsonParserForBug.Fields.project.key = system.Label.SBU_Licensing_System;
}
jsonParserForBug.fields.issuetype.name = 'Bug';
jsonParserForBug.fields.Customfield_11500.value = jiraCaseRecord.Jira_Reproducibility__c;
jsonParserForBug.fields.summary = jiraCaseRecord.Jira_Summary__c;
jsonParserForBug.fields.description = jiraCaseDescription;
jsonParserForBug.fields.customfield_10408 = jiraCaseRecord.Jira_Customer_Info__c;
jsonParserForBug.fields.customfield_13961 = jiraCaseRecord.Name;
}
if(jiraCaseRecord.Jira_Issue_Type__c == 'Enhancement'){
createTicketInJIRA(string.valueof(JSON.Serialize(jsonParserForEnhancement)));
}
else{
createTicketInJIRA(string.valueof(JSON.Serialize(jsonParserForBug)));
}
}
}
}
@VKAPS Dev(callout=true)
public static void createTicketInJIRA(string requestBody){
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://domain.atlassian.net/rest/api/2/issue');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json;charset=UTF-8');
Blob headerValue = Blob.valueOf('USERNAME' + ':' + 'APITOKEN');
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
request.setHeader('Authorization', authorizationHeader);
System.debug('requestbody: ' + requestBody);
request.setBody(requestBody);
System.debug('request is: ' + string.valueOf(request));
HttpResponse response = http.send(request);
if (response.getStatusCode() != 200) {
System.debug('The status code returned was not expected: ' +
response.getStatusCode() + ' ' + response.getStatus() + ' Response body: ' + response.getBody());
} else {
System.debug('Respponse body is: ' + response.getBody());
}
}
}