You need to sign in to do that
Don't have an account?
Jamurai
Test Class System Assert is successful but Trigger on EmailMessage has no coverage
I have a really basic trigger on the EmailMessage object that updates the Case Status when an incoming email is inserted. The trigger works just fine in testing and in my test class the System.assert passes. However, the trigger has 0% test coverage and I am not able to deploy to production. Are there limitations with this object that I'm not aware of? Any idea why this is happening?
trigger updateCaseStatus on EmailMessage (before insert) { List<String> applicableStatus = new String[]{ 'Support Agent Working - Resp Provided', 'Resolved - Waiting for Customer Approval', 'Waiting for Customer'}; Set<Id> caseIds = new Set<Id>(); for (EmailMessage em : Trigger.new) { // if it is an inbound email if (em.Incoming) { // add Case Id to caseIds set caseIds.add(em.ParentId); } } // query for Cases to update List<Case> casesToUpdate = [SELECT Id, Status FROM Case WHERE Id IN :caseIds AND Status IN :applicableStatus]; if (!casesToUpdate.isEmpty()) { for (Case c : casesToUpdate) { c.Status = 'Customer Response Provided'; } update casesToUpdate; } }
@isTest private class updateCaseStatus_Test{ static void testInboundEmail() { // create test case Case testCase = new Case( Subject = 'Test case01', Priority = 'P1 - Emergency'); testCase.Status = 'Waiting for Customer'; insert testCase; // System.debug('testCase: ' + testCase); // create test email message EmailMessage em = new EmailMessage( Incoming = TRUE, FromAddress = 'someone@somewhere.com', ToAddress= 'someone@nutanix.com', Subject = 'Test email', TextBody = 'Test', ParentId = testCase.Id); Test.startTest(); insert em; // System.debug('em: ' + em); // query and system assert Case c = [SELECT Id, Status FROM Case WHERE Id = :testCase.Id LIMIT 1]; System.assert(c.Status == 'Customer Response Provided'); Test.stopTest(); } }
You test method signature is missing the testmethod keyword.
You have: static void testInboundEmail()
Instead, you should actually have: static testmethod void testInboundEmail()
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
All Answers
You test method signature is missing the testmethod keyword.
You have: static void testInboundEmail()
Instead, you should actually have: static testmethod void testInboundEmail()
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank