2

I try to insert one record in Case object along with case comments, inorder to cover my apex class. However i got an error "Compile Error: Invalid type: CaseComments".Could you please help me how to insert case comments in case object.

Case cse = new Case();
 cse.Accountid = u1.Accountid;
 cse.Contactid = u1.contactid;
 cse.Description = 'TestDescription';
 cse.Status = 'New';
 cse.URLS__c = 'TestBiceUrls';
 cse.casecomment = 'test';
 cse.Subject = 'TestSubject';

 insert cse;
1
  • The way you described the question now makes it hard to fully understand the problem. Can you update the question with what you tried so far? Apr 28, 2016 at 8:19

1 Answer 1

4

Case Comment is not a field in Case. It is a separate child object to the case.

Case cse = new Case();
cse.Accountid = u1.Accountid;
cse.Contactid = u1.contactid;
cse.Description = 'TestDescription';
cse.Status = 'New';
cse.URLS__c = 'TestBiceUrls';
cse.Subject = 'TestSubject';

insert cse;

CaseComment cc = new CaseComment(ParentId = cse.Id,CommentBody = 'test');
insert cc;

CaseComment SObject documentation for your reference.

Hope it helps.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .