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
mahesh p 54mahesh p 54 

where am i going wrong in my test method?

@AuraEnabled
    public static void sendAnEmailAndActivity(String oppId,Id attachId){
        
        try{
            //DocumentItem doc = new DocumentItem();  
            List<String> toAddress = new List<String> ();
            List<String> fileList = new List<String>();
            Verification_Documents__c lId = [select Id from Verification_Documents__c where Attachmentid__c=:attachId];
            ContentDocumentLink att = [select Id, LinkedEntityId, ContentDocumentId,
                                       ContentDocument.ParentId from ContentDocumentLink where ContentDocument.Id = :attachId and LinkedEntityId=:lId.Id];
            //Verification_Documents__c associatedVd = [select Id,Approved__c,Reviewed__c,docType__c from 
            //                                          Verification_Documents__c where Id = :att.LinkedEntityId];
            //ContentDocument att = [select Id, ParentId from ContentDocument where Id = :attachId];
            Verification_Documents__c vd = [SELECT Id,Name,docType__c,Approved__c,Document_Master__r.Document_Name__c,Document_Master__r.User__c,Comment__c,
                                            Document_Master__r.Stages__c,Opportunity__r.customer__r.email,Opportunity__r.OwnerId,Opportunity__r.Sales_Contractor__r.Id, 
                                            Opportunity__r.Sales_Contractor__r.Email FROM Verification_Documents__c where Opportunity__c =: oppId AND Id =: att.LinkedEntityId];
            system.debug('approvalVal*****'+vd.Approved__c);
            if(vd.Approved__c == False){
                if(vd.Document_Master__r.User__c == 'Contractor'){
                    toAddress.add(vd.Opportunity__r.Sales_Contractor__r.Email); 
                }else if(vd.Document_Master__r.User__c == 'Customer'){
                    toAddress.add(vd.Opportunity__r.customer__r.Email);
                }
            }
            EmailTemplate emailTemp = [SELECT Id, Name, Body, HtmlValue FROM EmailTemplate where name='Documents Rejection']; 
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
            email.setToAddresses(toAddress);
            email.setSenderDisplayName('OakStar Team');
            if(vd.Document_Master__r.User__c == 'Contractor'){
                email.setTargetObjectId(vd.Opportunity__r.Sales_Contractor__r.Id);
            }else if(vd.Document_Master__r.User__c  == 'Customer'){
                email.setTargetObjectId(vd.Opportunity__r.customer__r.Id);
            }
            email.setWhatId(vd.Id);
            email.setTemplateId(emailTemp.id);   
            
            if(email != null){                
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email }); 
                if(vd.Approved__c == False){
                    if(vd.Document_Master__r.User__c == 'Customer'){
                        //Creation of Task
                        Task tsk = new Task();
                        tsk.Subject = 'Follow up with Customer';
                        tsk.WhatId = [select Id from Opportunity WHERE Id =: oppId].Id;
                        system.debug('WhatId****'+tsk.WhatId);
                        tsk.OwnerId = vd.Opportunity__r.OwnerId;
                        tsk.WhoId = vd.Opportunity__r.Sales_Contractor__r.Id;
                        system.debug('WhoId****'+tsk.WhoId);
                        tsk.Status = 'New';
                        tsk.Type = 'Other';
                        if(tsk.Type == 'Other' || tsk.Type == Null){
                            tsk.TaskSubtype = 'Task';
                            insert tsk;
                            system.debug('tsk****'+tsk); 
                        }
                        //tsk.Public = true;
                        //insert tsk;
                        //system.debug('tsk****'+tsk); 
                    }
                }
                system.debug('in email****'); 
            }                     
            
        }catch(Exception ex){
            System.debug('****Exception in SendEmail Method***'+ex.getMessage()+ex.getLineNumber());
        }
    }
My Test Method:
static testMethod void sendAnEmailAndActivityTest(){
        Opportunity oppty = TestDataBuilderClass.createOpportunity('Verification'); 
        TypeWiseDocument__c docs = TestDataBuilderClass.createdocuMaster();
        Verification_Documents__c vdFiles = TestDataBuilderClass.createverificationRecs(oppty.Id,docs.Id);        
        ContentVersion contentVersion = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.jpg',
            VersionData = Blob.valueOf('Test Content'),
            ContentLocation = 'S'
        );
        insert contentVersion;    
        ContentDocument documents = [SELECT Id, Title, ParentId, LatestPublishedVersionId FROM ContentDocument];
        //create ContentDocumentLink  record 
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = vdFiles.id;
        cdl.ContentDocumentId = documents.Id;
        cdl.shareType = 'I';
        insert cdl;
        
        //Attachment att = [select Id, ParentId from Attachment ];//where Id = :attachId
        Test.startTest();
        VerificationFilesControllerCD.sendAnEmailAndActivity(oppty.Id,cdl.Id);
        system.assertEquals(oppty.StageName, 'Verification');
        Test.stopTest();
    }


 
Raj VakatiRaj Vakati

I dnt see any issue .. can you please tell me which lines are not covering