+ Start a Discussion
songlansonglan 

Load Blob data with Test.loadData

Hello,

 

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

 HI..

 

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

C:\Export\myattachment.jpg

finally your csv file look like this
ParentId,Name,Body
50030000000VDowAAG,attachment1.jpg,C:\Export\attachment1.gif
701300000000iNHAAY,attachment2.doc,C:\Export\files\attachment2.doc
songlansonglan

Hi, 

 

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

 

 

songlansonglan

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 ..

http://www.salesforce.com/us/developer/docs/api_asynch/api_bulk.pdf

 

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

I hope you can get rid of this ploblem.