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;
  • 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? – Guy Apr 28 '16 at 8:19
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.