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
Sree07Sree07 

How to cover the lines for the following code in test class

for (ContentVersion document: documents) {           
  Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();                          attachment.setBody(document.VersionData);
                  attachment.setFileName(document.Title);
                  attachments.add(attachment);        
 }
mukesh guptamukesh gupta
Hi Sree,

Please follow below code:-
 
ContentVersion cvlist = new Contentversion(); 
cvlist.Title = 'Test'; 
cvlist.PathOnClient = 'Test'; 
cvlist.VersionData = EncodingUtil.base64Decode('Unit Test Attachment Body'); 
List<ContentVersion> cvl = new List<ContentVersion>(); 
cvl.add(cvlist); 
insert cvl;

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh