function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
abhishek g 16abhishek g 16 

How to write a trigger on Case Object whenever a case is identified in case object and it should create a issue in JIra..??

I am having a issue in Trigger. Its unable to fire..

trigger CreateWithJIRAIssue on Case (after insert) {
List<Case> escCases = new List<Case>();
  

   for (Case c : Trigger.new){

    // all the cases that have status as abc' is added to a list called xCases
    if(c.Status == 'abc'){
     xCases.add(c);
    }
   }
   if(xCases != null && xCases.size()>0){
    // now iterate over the selected cases and call the web service
    for(Case c : xCases){
     //call webservice
     system.debug('inside case ' + c.CaseNumber);
     //Define parameters to be used in calling Apex Class
     String jiraURL = 'http://jira';
     String systemId = '2';
     String objectType ='Case';
     String objectId = c.id;
     String projectKey = 'LEV';
     String issueType = 'BUG';
     System.debug('\n\n status is escalated');
     //Execute the web service call
     
     JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
    }
   }
  }
}
}
Best Answer chosen by abhishek g 16
AnupPrakash_AlgoworksAnupPrakash_Algoworks
Since you are performing a Callout here as it is an integration with Jira. I would recommend that you create a service class that would be creating the object and initiating the callout request in an asynchronous mode (Because Trigger runs in a Synchronous mode and does not support callouts) . 
public class serviceClass {
	@future
	public static void createIssue(String jiraURL,String  systemId ,String objectType,String objectId,String projectKey,String issueType ){
		JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
	}
}
Doing so would still keep your original code synchronous when you need it work in a Synchronous mode.


Please Mark as Best answer if it resolves your query.

All Answers

ManojjenaManojjena
Hi Abhishek,

Is your webservice class method is annotated with future annotation.(@future).
If no then add that and if no what is the error you are getting ?
 
AnupPrakash_AlgoworksAnupPrakash_Algoworks
Since you are performing a Callout here as it is an integration with Jira. I would recommend that you create a service class that would be creating the object and initiating the callout request in an asynchronous mode (Because Trigger runs in a Synchronous mode and does not support callouts) . 
public class serviceClass {
	@future
	public static void createIssue(String jiraURL,String  systemId ,String objectType,String objectId,String projectKey,String issueType ){
		JIRAConnectorWebserviceCallout.CreateIssue(jiraURL, systemId ,objectType,objectId,projectKey,issueType);
	}
}
Doing so would still keep your original code synchronous when you need it work in a Synchronous mode.


Please Mark as Best answer if it resolves your query.
This was selected as the best answer
abhishek g 16abhishek g 16
Thank you Manoj & AnupPrakash for your replies . Its working :)
 
Rahavan Arumugam AlameluRahavan Arumugam Alamelu
Hi Abhishek, 

Can you please send me the code of the JIRAConnectorWebserviceCallout. We have a requirement that the jira issue should be createad automatically from the salesforce. 

​Appreciate your help.