Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Trigger SynchronizeWithJIRAIssue on Case (after update) {
- if (JIRA.currentUserIsNotJiraAgent()) {
- if(System.isFuture() == false || System.isBatch() == false || System.isScheduled() == false) { //Check, If Not in any Async Apex context, only then execute the Future Method.
- system.debug('System.isFuture()---->'+System.isFuture());
- system.debug('System.isBatch()--->'+System.isBatch());
- system.debug('System.isScheduled()--->'+System.isScheduled());
- system.debug('entering@@@@@@@@');
- system.debug('@@@@JIRA.currentUserIsNotJiraAgent()@@@@----->'+JIRA.currentUserIsNotJiraAgent());
- for (Case c : Trigger.new) {
- String objectType ='Case'; //Please change this according to the object type
- String objectId = c.Id;
- JIRAConnectorWebserviceCalloutSync.synchronizeWithJIRAIssue(JIRA.baseUrl, JIRA.systemId, objectType, objectId);
- }
- }
- }
- global class JIRAConnectorWebserviceCalloutSync {
- @future (callout=true)
- WebService static void synchronizeWithJIRAIssue(String baseUrl, String systemId, String objectType, String caseId) {
- system.debug('baseurl@@@@@----->'+baseUrl+'systemId@@@---->'+systemId+'objectType@@@@--->'+objectType+'casid@@@@---->'+caseId);
- try {
- HttpRequest req = buildRequest(baseUrl, JIRA.username, JIRA.password, systemId, objectType, caseId);
- JIRA.sendRequest(req);
- } catch(System.CalloutException e) {
- System.debug(e);
- }
- }
- // Constructs request needed to synchronize a JIRA issue from provided parameters.
- public static HttpRequest buildRequest(String baseUrl, String username, String password,
- String systemId, String objectType, String caseId) {
- HttpRequest req = new HttpRequest();
- String basicAuthHeader = JIRA.authHeader(username, password);
- String endpoint = getEndpoint(baseUrl, systemId, objectType, caseId);
- system.debug('end point @@@@@------>'+endpoint);
- system.debug('basicAuthHeader@@@@----->'+basicAuthHeader);
- req.setHeader('Authorization', basicAuthHeader);
- req.setHeader('Content-Type', 'application/json');
- req.setHeader('Content-Length', '0');
- req.setEndpoint(endpoint);
- req.setMethod('PUT');
- return req;
- }
- // Creates the endpoint to synchronize the issue from provided parameters.
- private static String getEndpoint(String baseUrl, String systemId, String objectType, String caseId) {
- return baseUrl + '/rest/customware/connector/1.0/' + systemId + '/' + objectType + '/' + caseId + '/issue/synchronize.json';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement