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

Load Blob data with Test.loadData



I'd like to use Test.loadData to create some attachments with createddate in the past for test purpose. What should I put for the Body field (base64) in the csv file?


Thanks in advance.

V AnandV Anand



You can use this code to cover blob value in test case


Attachment at= new Attachment();

at.body=blob.valueof('this is test attachment');


In  CSV file

use the  local address path of the uploading file like


finally your csv file look like this



Thanks for your quick response.


I tried with the local path in the csv file, and I got System.StringException: CSV Parse error: Body: value not of required type

V AnandV Anand

You need to enable the bulk API  with enable to upload binary attachments in dataloader settings.


Goto dataloader ---settings in that  select "Use bulk API" below there is another option called "upload bulk API Batch as Zip file (Enable to upload binary attachments) " select this and save ,


Then you can perform your operation on attachments




ah sorry I'm not using dataloader. I talked about using the method Test.loadData() in unit test.


I can insert attachments with apex code, but this way the created date will be the date of today and it can not be modified, so I tried to use Test.loadData(name of a file) with which I can insert attachments with a specified created date, but I don't know what to put in the Body field.

V AnandV Anand

Follow the instructions in below link ..


in that pdf  goto  the topic "Load Binary attachment." 

I hope you can get rid of this ploblem.