You need to sign in to do that
Don't have an account?
Brandon Wermes
Not getting code coverage on trigger
Hello all,
I have a fairly simple trigger. When a CaseComment is created, the trigger creates a new FeedItem using the CommentBody as the Body of the FeedItem and the ParentId of the CaseComment as the FeedItem.Parent Id. The trigger executes as expected & designed in Sandbox, however when I run my Test Class to obtain Code Coverage, I'm getting 0%. Trigger & Class below. Any help is appreciated!
Trigger
Test Class
Thank you!
I have a fairly simple trigger. When a CaseComment is created, the trigger creates a new FeedItem using the CommentBody as the Body of the FeedItem and the ParentId of the CaseComment as the FeedItem.Parent Id. The trigger executes as expected & designed in Sandbox, however when I run my Test Class to obtain Code Coverage, I'm getting 0%. Trigger & Class below. Any help is appreciated!
Trigger
trigger CaseCommentToFeed on CaseComment (after insert) { List<FeedItem> updates = new List<FeedItem>(); for(CaseComment cc : trigger.new){ if (cc.ParentId.getSObjectType() == Case.SObjectType) { updates.add(new FeedItem( ParentId = cc.ParentId, CreatedById = cc.CreatedById, Title = 'New Comment Post!', Body = cc.CommentBody )); } insert updates; } }
Test Class
@isTest(SeeAllData=true) public class TestCaseInsert { static testMethod void insertNewCase() { Case caseToCreate = new Case(); caseToCreate.Status = 'New'; caseToCreate.Priority = 'Normal'; caseToCreate.Origin = 'Phone'; caseToCreate.Subject = 'Subject Here'; caseToCreate.Description = 'Description Here'; insert caseToCreate; CaseComment commentToCreate = new CaseComment(); commentToCreate.CommentBody = 'This is the body'; commentToCreate.ParentId = caseToCreate.Id; insert commentToCreate; } }
Thank you!
It is working fine. I only copy pasted your code. Can you please run the test class again and recheck?
Mark this question as solved if this helps you and choose the best answer.
Regards,
Santosh Chitalkar
I'm not getting any errors and the trigger is executing properly in Sandbox. The trouble is in getting code coverage via the Test Class. If I run the test class, I'm getting zero code coverage. If I bundle the trigger with the test class and upload to production, on validation I'm getting a Code Coverage Error.