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
karthikeya 2karthikeya 2 

test code for Attachment

Hi all,
 
hoe to write the code coverage for the following lines,

private void getAttachmentInfo(){
        listAttachments = [SELECT ParentId , Name,  BodyLength,  Id,   CreatedDate     FROM  Attachment   WHERE ParentId = :taskid
                            ORDER BY CreatedDate DESC   LIMIT 50 ];    
    
        for(Attachment a : listAttachments) {
            String size = null;
            if(1048576 < a.BodyLength){
                // Size greater than 1MB
                size = '' + (a.BodyLength / 1048576) + ' MB';
            }
            else if(1024 < a.BodyLength){
                // Size greater than 1KB
                size = '' + (a.BodyLength / 1024) + ' KB';            
            }
            else{
                size = '' + a.BodyLength + ' bytes';
            }
            mapAttachmentSize.put(a.id, size);
        }
    }