One trigger per object
If you have one Apex trigger listening to multiple events (e. g. after insert and after update) you can still use the Apex API to create Jira issues and/or push updates to Jira. Sometimes, though, you want to call the API conditionally based on the actual event. In that case you can do so by adding some checks per case:
Note that for issue creation you need to, respectively, hardcode the Jira project id and Jira issue type id. You can get this 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.
Apex test class for the trigger
Depending on which trigger events (after insert or after insert) are used in the trigger you have to call the corresponding test helper method.
As with the trigger itself, you may need a test for each object trigger. All you have to do is replace
Case in the above code with the actual object name.
After creating your test class, click Run Test. This ensures the test gets associated with your newly created trigger and provides code coverage.
You will need to re-run the Apex class if you ever deactivate and reactivate the trigger.
The Apex API and test helper methods work as well with any custom object. You just need to find out the object name (e.g.:
MyObject__c) and use it in the trigger and test code as documented above.
If you have other triggers with Webservice callouts that are executed as a result of running this test, you might get an error message like this:
In order to fix this error, you need to specify a fake response for the callouts. JiraTriggerTestHelper already provides a mock for its test method, but it will not mock other webservice callouts. Therefore, you may need to provide your own implementation of HttpCalloutMock.
Please customize the following code according to your callout method:
Then, set the mock before the JiraTriggerTestHelper test method is called.
Also note that the Push API should not be called from within a Future. When called from a Future, the Push API simply logs it as a warning. Check your Apex Logs to see if that is the case if the automatic synchronization is not working.
For more details, please refer to the Salesforce documentation.