Skip to main content
Skip table of contents

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

CODE
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:

CODE
if(result.hasError()){
    System.debug(System.LoggingLevel.ERROR,result.getErrorMessage());
}

Upon successful execution, Issue Comment ID is returned as follows:

CODE
System.debug(System.LoggingLevel.INFO,'Issue comment Id: '+result.getIssueCommentId());

Comment ID can be used for updating the Comment.

Creating an Issue for a different Jira Connection

If, as in the example above, the Jira Connection ID is not specified, the comment will be posted to the Jira marked as 'Default' in zAgileConnect Settings:

For specifying a different Jira, you must know the Connection ID related to that Jira.  You can find the Connection ID in zAgileConnect Settings:

The Jira Connection ID is a unique identifier to be used when calling the zAgileConnect API, to specify a Jira.  To post a comment for the Jira JccJiraCloud, specify its Jira Connection ID j01 when calling the method:

CODE
zsfjira.ZCBeans.IssueCommentResult result = zsfjira.ZC.Issues.createJIRAIssueComment('j01', 'SEL-118','Comment test');

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:

CODE
zsfjira.ZCBeans.IssueCommentResult result = zsfjira.ZC.Issues.updateJIRAIssueComment('SEL-118','12693','Comment test(edited)');

For updating an existing Issue Ccomment of a different Jira, specify its connection as the first parameter:

CODE
zsfjira.ZCBeans.IssueCommentResult result = zsfjira.ZC.Issues.updateJIRAIssueComment('j01', 'SEL-118','12693','Comment test(edited)');


The returned object contains the result of the operation. Errors may be handled as follows:

CODE
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:

CODE
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:

CODE
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());
		}
    }
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.