This guide will help you to configure Automatic Jira issue creation from Salesforce by configuring the required Salesforce triggers. This automation has some important prerequisites and conditions, as noted in the section below.
Prerequisites
The Salesforce Package must be installed and configured.
You will need to configure the available objects and fields before proceeding with other steps.
You will also need to confirm that you can manually create a Jira Issue from Salesforce. If the manual method does not work, then the automation will not work either.
Note that Automatic Jira issue creation will work only if:
Salesforce objects, from which you want to create Jira issues automatically, are configured to be available for the authorized connection.
Apex triggers for the respective objects are installed.
Create and deploy Apex triggers
...
Automatically create a Jira issue after a Salesforce Object is inserted
Cloud
CaseInsertedTrigger
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
trigger CaseInsertedTrigger on Case (after insert) { JCFS.API.createJiraIssue('1000', '10002'); } |
Server
CaseInsertedTrigger
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
trigger CaseInsertedTrigger on Case (after insert) { JSFS.API.createJiraIssue('1000', '10002'); } |
Note that you need to, respectively, hardcode the Jira project id and Jira issue type id. You can get these values from the Jira REST API. In future versions of the package, there will be a feature helping admins generate the full code for the trigger from a template.
Automatically create a Jira issue after a Salesforce Object is updated
You can also create an issue automatically after an object is updated (e. g. in an after update trigger) as follows:
Cloud
For cloud administrators, you can choose either:
A trigger that automatically creates a new Jira issue and the post action respects the settings after creating the Jira issue. This was an enhancement introduced from JCFS 4.7 onwards to deliver on a popular request at our idea portal.
CaseUpdatedTrigger
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
trigger CaseUpdatedTrigger on Case (after update) { JCFS.API.createJiraIssueWithDefaultPostAction('1000', '10002'); } |
A trigger that omits any post action once the Jira issue is created
CaseUpdatedTrigger
Code Block language java theme Eclipse title CaseUpdatedTrigger linenumbers true trigger CaseUpdatedTrigger on Case (after update) { JCFS.API.createJiraIssue('1000', '10002'); }
...
Once triggers are created, they need a certain level of test coverage to be allowed to deploy to the Production environment. The package contains a test helper which tests the whole scenario. You simply need to add a unit test for each trigger and call the test helper method. Depending on the trigger event (after insert or after update) you will have to call the corresponding test helper method. A sample of both tests is shown in the following example:
Cloud
CaseTriggerTest
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
@isTest public class CaseTriggerTest { @isTest static void caseAfterInsertTest() { JCFS.JiraTriggerTestHelper.testAfterInsert('Case'); } @isTest static void caseAfterUpdateTest() { JCFS.JiraTriggerTestHelper.testAfterUpdate('Case'); } } |
Server
CaseTriggerTest
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
@isTest public class CaseTriggerTest { @isTest static void caseAfterInsertTest() { JSFS.JiraTriggerTestHelper.testAfterInsert('Case'); } @isTest static void caseAfterUpdateTest() { JSFS.JiraTriggerTestHelper.testAfterUpdate('Case'); } } |
...
A trigger that automatically creates a new Jira issue and the post action respects the settings after creating the Jira issue. This was an enhancement introduced JCFS 4.7 onwards to deliver on a popular request at our idea portal
...
...
Signature of JCFS.API.createJiraIssueWithDefaultPostAction
Code Block | ||
---|---|---|
| ||
trigger CaseInsertedTrigger on Case (after insert) { List<Case> toBeCreated = new List<Case>(); for(Case c : Trigger.new) { toBeCreated.add(c); } JCFS.API.createJiraIssueWithDefaultPostAction('10300', '10001', toBeCreated, Trigger.old); } |
A trigger that omits any post action once the Jira issue is created
...
Signature of JCFS.API.createJiraIssue
Code Block | ||
---|---|---|
| ||
trigger CaseInsertedTrigger on Case (after insert) { List<Case> toBeCreated = new List<Case>(); for(Case c : Trigger.new) { toBeCreated.add(c); } JCFS.API.createJiraIssue('10300', '10001', toBeCreated, Trigger.old); } |
Server
...
...
Signature of JCFS.API.createJiraIssue
Code Block | ||
---|---|---|
| ||
JSFS.API.createJiraIssue(String JiraProjectId, String JiraIssueTypeId, List<SObject> newObjects, List<SObject> oldObjects) |
...
For instance, if you want to create Jira issues only from Cases whose summaries start with Post
you can use the following trigger code:
Cloud
...
...
Selective automatic JIRA issue creation
Code Block | ||
---|---|---|
| ||
trigger CaseInsertedTrigger on Case (after insert) { List<Case> toBeCreated = new List<Case>(); // proper runtime type, List<SObject> won't work for(Case c : Trigger.new) { if(c.Subject.startsWithIgnoreCase('Post')) { toBeCreated.add(c); } } JCFS.API.createJiraIssue('10300', '10001', toBeCreated, Trigger.old); } |
Server
...
...
Selective automatic JIRA issue creation
Code Block | ||
---|---|---|
| ||
trigger CaseInsertedTrigger on Case (after insert) { List<Case> toBeCreated = new List<Case>(); for(Case c : Trigger.new) { toBeCreated.add(c); } JSFS.API.createJiraIssueWithDefaultPostAction('10300', '10001', toBeCreated, Trigger.old); } |
...