+ Start a Discussion
FengFeng 

How to assign value to body field of an attachment record ?

when i try to create an attachment record in my testmethod
 
Code:
Attachment newatt = new Attachment();
  newatt.Name = 'test attachment';
  newatt.Body = 0;
  newatt.ParentId = obj.Id;
  insert newatt;

the code  newatt.Body = 0; failed
how to assign value to the body field as this field is base64 data type
 
thanks in advance
 
Feng
ESES
body is of type blob in apex. Look for examples of blob in apex dev-guide. simple example to convert string to blob is below,
Code:
blob b = blob.valueof('hello');