Проблема покрытия кода в Salesforce для версий контента и классов сообщений - PullRequest
0 голосов
/ 21 октября 2019

Я пытаюсь создать тестовый класс, но не могу получить покрытие кода для версии контента и класса обмена сообщениями. Я попытался вставить версию контента и ссылку на документ контента в тестовый класс, но он не работает.

global class MergePDF_Controller {


    @future (callout=true)
    public static void save(Id id){

        System.debug('Case Id ' + id);
        PageReference pagePdf = new PageReference('/apex/em'); 
        pagePdf.getParameters().put('id', id);

        Case cs = [ select Correction_file_number__c, Corrections_needed__c, CaseNumber, Household__c, PropertyCase__c, Created_By_Email__c, OwnerId, Owner_Name__c, Last_modified_by__c, Owner_Email__c from Case where Id=: id ];

        Property_records__c property = [select Name from  Property_records__c where Id =: cs.PropertyCase__c ];

        Blob pdfPageBlob;
        pdfPageBlob = pagePdf.getContentAsPDF(); 



      /*  Attachment attach = new Attachment(); 
        attach.Body = pdfPageBlob;
        attach.Name = 'CorrectionCounter_'+cs.Correction_file_number__c+'.pdf';
        attach.IsPrivate = false;
        attach.ParentId = id;
        */

        ContentVersion cv = new ContentVersion(); 
        cv.ContentLocation = 'S'; 
        cv.PathOnClient = 'CorrectionCounter_'+cs.Correction_file_number__c+'.pdf';
        cv.Origin = 'H'; 
        cv.Title ='CorrectionCounter_'+cs.Correction_file_number__c+'.pdf';
        cv.VersionData = pdfPageBlob;

        insert cv; 

        ContentVersion content = [select ContentDocumentId from ContentVersion where Id =: cv.Id]; 

        ContentDocumentLink cl = new ContentDocumentLink(LinkedEntityId = id, ContentDocumentId = content.ContentDocumentId, ShareType = 'I'); 

        insert cl;


        Messaging.SingleEmailMessage mailTest = new Messaging.SingleEmailMessage();
        String[] toAddressesTest = new String[]{cs.Created_By_Email__c};
            mailTest.setToAddresses(toAddressesTest); 
        mailTest.setSubject('Case Correction Requested');
        mailTest.setHtmlBody('Your case is required a few corrections');

        List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
        // Add to attachment file list
        Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
        efa.setFileName('CorrectionCounter_'+cs.Correction_file_number__c+'.pdf');
        efa.setBody(pdfPageBlob);
        fileAttachments.add(efa);
        mailTest.setFileAttachments(fileAttachments);

        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mailTest}); 




    }



}
...