+ Start a Discussion

attachments and test methods

I'm curious if anybody knows how to simulate a document "attachment" to a case object?  I'm trying to write a test method that is attaching a document to the case.  Here is what I have for the test so far...



static testMethod void ContactNullTest() { test.starttest(); Case testCase = new Case(); testCase.ContactId = null; ApexPages.StandardController sc = new ApexPages.StandardController(testCase); hdWebForm scExt = new hdWebForm(sc); testCase = (Case)sc.getRecord(); Contact objContact; String UserDepartment; String UserLocation; ID currUserID = UserInfo.getUserID(); //UserID = currUserID; Boolean blnHasContactAssociated; test.stoptest(); }





Try this after inserting the testCase record:

Attachment attachment = new Attachment();
attachment.body = Blob.valueOf( 'this is an attachment test' );
attachment.name = 'fake attachment';

attachment.parentId = testCase.id;

insert attachment;