Test Class runs successfully and test coverage is 100% but fails during deployment saying "Your Code Coverage is 70%".

public class DefaultSignatureForEmail_Test {

    static {

    Static testMethod void TestDefaultSignatureForEmail() {

        Account account = new Account();
        account.name = 'test account';
        account.Customer_Party_Id__c = '123456789';
        insert account;

        Contact contact = new Contact();
        contact.AccountId = account.id;
        contact.Email = '[email protected]';
        contact.LastName = 'TestLastName';
        insert contact;

        List<Case> tCases = new List<Case>();
        Case tCase = new Case(Subject = 'OneCase', AccountId = account.Id);
        insert tCase;

        Exception failureDuringExecution = null;

        //Create QuickActionDefaults test data here
        String defaultsAsJSON = '[{"targetSObject":{"attributes":{"type":"EmailMessage"},"TextBody":"",'
            + '"FromName":"Test","FromAddress":"[email protected]","HtmlBody":"<html><body></body></html>","BccAddress":"[email protected]",'
            + '"CcAddress":"","ToAddress":"[email protected]","Subject":"Testing"},"contextId":"'+tCase.Id+'","actionType":"Email",'
            + '"actionName":"Case.Email","fromAddressList":["[email protected]"]}]';
        List<QuickAction.SendEmailQuickActionDefaults> defaultsSettings = 
            (List<QuickAction.SendEmailQuickActionDefaults>)JSON.deserialize(defaultsAsJSON, List<QuickAction.SendEmailQuickActionDefaults>.class);
        try { 
            (new DefaultSignatureForEmail()).onInitDefaults(defaultsSettings); 
        catch(Exception failure) { 
            failureDuringExecution = failure; 

        System.assertEquals(null, failureDuringExecution, 'There was an exception thrown during the test!');


enter image description here

enter image description here

but when other dev ran the same test, lines 20, 21 & 22 were showing not covered. I am not sure how is that happening. Could someone help me with how to set the templateId for SendEmailQuickActionDefaults in the test class?

1 Answer 1


Silly thing! I didn't had a user in test class where Use_Default_Signature is set. This did the trick!

Id loggedInUserId = UserInfo.getUserId();
        User adminUser = [SELECT Id FROM User WHERE Id = :loggedInUserId];
        adminUser.Use_Default_Signature__c = true;
        update adminUser;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .