You need to sign in to do that
Don't have an account?
Chinnodu
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body] in test class
Hi Experts,
I have written a test class , test method does not passed and i got cobut i am getting below error. how to i will fix , kindly suggest me.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body].
public class caseattachment
{
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
public caseattachment(Apexpages.standardcontroller controller)
{
objcase = new case();
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
Integer i=0;
myAttachment .clear();
myAttachment.Body = fileBody;
myAttachment.Name = 'Logo_'+objcase.id+'.jpeg' ;
myAttachment.ParentId = objcase.id;
insert myAttachment;
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
Please see attached the my screen shot
I have written a test class , test method does not passed and i got cobut i am getting below error. how to i will fix , kindly suggest me.
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Body]: [Body].
public class caseattachment
{
public case objcase{get;set;}
public Attachment myAttachment{get;set;}
public string fileName{get;set;}
public Blob fileBody{get;set;}
public caseattachment(Apexpages.standardcontroller controller)
{
objcase = new case();
myAttachment =new Attachment();
}
public pagereference save()
{
insert objcase;
System.debug('@@@@@fileBody'+fileBody);
myAttachment = new Attachment();
Integer i=0;
myAttachment .clear();
myAttachment.Body = fileBody;
myAttachment.Name = 'Logo_'+objcase.id+'.jpeg' ;
myAttachment.ParentId = objcase.id;
insert myAttachment;
pagereference pr = new pagereference('/'+objcase.id);
return pr;
}
}
Please see attached the my screen shot
@isTest private class caseattachment1{ static testMethod void testCaseExt() { // Create the Case Record. Case cas = new Case( Priority = 'Medium',Status= 'Working',Origin= 'Phone'); insert cas; Attachment attach=new Attachment(); attach.Name='Unit Test Attachment'; Blob fileBody=Blob.valueOf('Unit Test Attachment Body'); attach.body=fileBody; attach.parentId=cas.id; insert attach; ApexPages.StandardController sc = new ApexPages.StandardController(cas); caseattachment cec= new caseattachment(sc); cec.save(); } }
Please try this once