You need to sign in to do that
Don't have an account?
viv1
testmethod for attachment ??
i am writing test for controller
having attachment functionality !!
this is my code..
Blob b = Blob.valueOf('Test Data');
Attachment attachment = new Attachment();
attachment.ParentId =doc.Id;
attachment.Name = 'Test Attachment for Parent';
attachment.Body = b;
insert attachment;
but is giving
error : System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body]
That code should work - I've just tried it on my dev org.
What type is 'doc' that is the parent of the attachment?
Attachment vAttachment = new Attachment();
vAttachment.Name = 'File';
vAttachment.ParentId = vLstOppty[i].Id;
vAttachment.ContentType = '.txt';
vAttachment.Body = Blob.valueOf('Test Data');
insert vAttachment;
I thinks you have missed ContentType field. Please mark it, if it helps you.