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
Daymon BoswellDaymon Boswell 

First Apex Trigger Deployment - Fails When Deploying in Production

Hi everyone, 

I am not a developer and am attempting to push my first trigger from Sandbox to Production and need some help. I've created this trigger: 

trigger CasetoJiraPayTeamBug on Case (after Update) {
    for(Case obj: Trigger.new) {
        if(obj.Send_to_Jira__c == true && obj.Pay_Team__C == true && obj.Bug_Report__C == true){
       {
          JCFS.API.createJiraIssue('10429', '1');
       }
   }
}
}

I used a thrid party app that generated this test class for me:

@isTest
private class CaseTrigger_Test{
  static testMethod void test_CaseTrigger(){
   test.startTest();
    Case case_Obj = new Case(Send_to_Jira__c = True, Product_Team__c = 'Pay Team',Type = 'Bug Report');
    Insert case_Obj; 
   test.stopTest();
  }

  static testMethod void test_UseCase1(){
   test.startTest();
    Case case_Obj = new Case(Send_to_Jira__c = True, Product_Team__c = 'Pay Team',Type = 'Bug Report');
    Insert case_Obj; 
    test.stopTest();
}
}


My deployemnt fails with an error message of: Your code coverage is 0%. You need at least 75% coverage to complete this deployment.
GovindarajGovindaraj
Hi Daymon,

Please try below test class,
 
@isTest
Private Class caseTrigger_Test {
	@isTest
	static void test_method_one() {
		Case objCase = new Case(); //Fill required fields like below
		objCase.Status ='New';
		objCase.Priority = 'Medium; 
		objCase.Origin = 'Emai;
		objCase.Send_to_Jira__c = true;
		objCase.Pay_Team__C = true;
		objCase.Bug_Report__C = true;
        	Insert objCase;
		list<Case> lstCase = [SELECT Id FROM CASE];
		System.assertEquals(1, lstCase.size());

		objCase.Priority = 'Low';
		Update objCase;
		list<Case> lstCase = [SELECT Id, Priority FROM CASE];
        	System.assertEquals('Low',lstCase[0].Priority);
	}
}

Please let us know, if this helps.

Thanks,
Govindaraj.S
Daymon BoswellDaymon Boswell
Thank you Govindaraj,

I appreciate your help with this. When I put this code in the devloper consule it gives me an error at line 18 saying "Duplicate Variable:1stCase" Do you know how I should resolve that?
GovindarajGovindaraj
Change the variable to some other like below,
list<Case> lstCase2 = [SELECT Id, Priority FROM CASE];
Daymon BoswellDaymon Boswell
Thank you Govinderaj, I made that update and recieved no errors when saving. I went to Apex Test Execution and the Test failed wit the following error:

System.SobjectExcemption: SObject row was retrieved via SOQL without querying the Class.caseTrigger_Test.test_method_one: Line 19, Column 1