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
PrattyPratty 

Test method for Attachment

Hello All,

 

I want to write a test method for a class but fail to cover some part because of BodyLength of Attachment object.

 

Here is some part of code,

.....................

if(objAttachment.BodyLength > 0)

{...................}

 

So could you help me how to set value for this BodyLength field.

 

Thanks,

Pratty

 

Jerun JoseJerun Jose
The documentation says that BodyLength is the Size of the file (in bytes). So if you set some body value, I'm guessing that the bodylength should become greater than 0.

To set the body, you can create your own blob value, by doing something like
Blob myBlob = Blob.valueof('myTestValue');
and then assign myBlob as
atchmnt.Body = myBlob;