zAgileConnect API – Creating Issue Comments from Salesforce – Usage & Examples
Requires the user executing the API to have a valid zAgileConnect license
Create Issue Comment
To create a comment in an Issue from Salesforce, use the method ZC.Issues.createJIRAIssueComment and send as parameters the Issue Key or Issue ID followed by the comment body
zsfjira.ZCBeans.IssueCommentResult result = zsfjira.ZC.Issues.createJIRAIssueComment('SEL-118','Comment test');
The returned object contains the result of the operation. Errors may be handled as follows:
if(result.hasError()){
System.debug(System.LoggingLevel.ERROR,result.getErrorMessage());
}
Upon successful execution, Issue Comment ID is returned as follows:
System.debug(System.LoggingLevel.INFO,'Issue comment Id: '+result.getIssueCommentId());
Comment ID can be used for updating the Comment in the future.
Update Issue Comment
To update a Comment, use the method ZC.Issues.updateJIRAIssueComment and send as parameters the Issue Key or Issue ID, the Comment ID and the Comment body:
zsfjira.ZCBeans.IssueCommentResult result = zsfjira.ZC.Issues.updateJIRAIssueComment('SEL-118','12693','Comment test(edited)');
The returned object contains the result of the operation. Errors may be handled as follows:
if(result.hasError()){
System.debug(System.LoggingLevel.ERROR,result.getErrorMessage());
}
Issue Comment Listener
You can create your own custom listener in which you will receive the events associated with Issue Comments (Posts and Updates).
The listener will only receive events of Comments whose Issues have at least one related Salesforce entity and the Comment body contains the hashtag #Salesforce.
Create a class and implement the interface zsfjira.ZJIRACommentListener and override the method processIncomingCommentEntries:
global class CommentListener implements zsfjira.ZJIRACommentListener{
global void processIncomingCommentEntries(List<zsfjira.ZJiraCommentsService.ZJiraCommentEntry>pentries){
//TODO
}
}
When an Issue Comment is created or updated (and contains #salesforce), your method will be invoked, receiving a collection of ZJiraCommentsService.ZJiraCommentEntry.
This class contains the following methods that may be used for accessing the Comment information:
- getBody() returns a String with the body of the Comment.
- getIssueId() returns the Issue ID as a String.
- getIssueKey() returns the Issue Key as a String.
- getIssueCommentId() returns the Issue Comment ID as a String.
You can iterate the list to process all incoming Comments:
global class CommentListener implements zsfjira.ZJIRACommentListener{
global void processIncomingCommentEntries(List<zsfjira.ZJiraCommentsService.ZJiraCommentEntry> pentries){
for(zsfjira.ZJiraCommentsService.ZJiraCommentEntry entry: pentries){
System.debug(System.LoggingLevel.INFO,'Received JIRA Comment: ' +entry.getIssueCommentId());
}
}
}