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
Brandon WermesBrandon 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
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!
SantoshChitalkarSantoshChitalkar
Hello Brandon,

It is working fine. I only copy pasted your code. Can you please run the test class again and recheck?


 User-added image

Mark this question as solved if this helps you and choose the best answer.

Regards,
Santosh Chitalkar
bob_buzzardbob_buzzard
Do you see any errors when running your test? If not, is the trigger marked as Active in the meta-xml file?
Brandon WermesBrandon Wermes
Bob -

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.