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 = 'Test@test.com';
        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":"test@example.com","HtmlBody":"<html><body></body></html>","BccAddress":"test@example.com",'
            + '"CcAddress":"","ToAddress":"test@example.com","Subject":"Testing"},"contextId":"'+tCase.Id+'","actionType":"Email",'
            + '"actionName":"Case.Email","fromAddressList":["salesforce@test.com"]}]';
        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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.