+ Start a Discussion
Michael Webb 15Michael Webb 15 

Confused on Code Coverage for one trigger AttachmentTrigger, why am I getting 0% coverage?

Hello, I have a trigger that I think someone deployed with a Salesforce Labs app, it is very basic (I do not know apex very well). When I run all the tests through the developer console it shows we are at 80% coverage and this specific trigger gets 100% coverage.  However, when I use a change set to deploy any Apex code I get the following error.

AttachmentTrigger, Details: Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required

1
2
3 trigger AttachmentTrigger on Attachment (after insert) {
    TriggerUtility.updateCaseLastActivity(Trigger.New,'attachment');
}

I am not sure where to start if I need to write a test class for this, any suggestions and any idea why there is a difference? 

Thanks in advance
Michael
Chandra Sekhar CH N VChandra Sekhar CH N V
You are calling updateCaseLastActivity from a utility class. What exactly you are performing in that method? If you need just inserting attachment in test methods, try ​using the below 
Attachment attachment = new Attachment();  
    attachment.ParentId = parentId; (sObject ID) 
    attachment.Name = 'Test Attachment for Parent';  
    attachment.Body = b;        
    insert(attachment);

 
Michael Webb 15Michael Webb 15
Thank you!! I am not sure what the trigger is doing, this is the first time I saw it.  I tried your code and I am getting the following error.

Error: expecting a right parentheses, found 'ID' at line 8 column 45, which is right after sObject and before ID.

This is the full code.

Thanks!
 
@isTest
public class attachmentTrigger_Test {
  
  @isTest
  public static void AttachmentTest(){
    Test.startTest();
    Attachment attachment = new Attachment();  
    attachment.ParentId = parentId; (sObject ID) 
    attachment.Name = 'Test Attachment for Parent';  
    attachment.Body = b;        
    insert(attachment);

 
Chandra Sekhar CH N VChandra Sekhar CH N V
"(sObject ID)" is just a comment. Exclude it from your code.
Amit Chaudhary 8Amit Chaudhary 8
are you deploying Test class with Trigger in production ?