+ Start a Discussion
TraceyTracey 

Compile Error: Invalid field CommentBody for SObject Case

Could someboby please let me know why I'm getting this error?

 

Error: Compile Error: Invalid field CommentBody for SObject Case at line 8 column 23 trigger

 

UpdateCaseCom on Task (after insert)

{

String LastCaseComment;

Datetime DateFilter = Datetime.now().addSeconds(30);

for (Case dc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter])

{

   LastCaseComment = dc.CommentBody;

}

r insert) { String LastCaseComment; Datetime DateFilter = Datetime.now().addSeconds(30); for (Case dc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter]) { LastCaseComment = dc.CommentBody; }
Vijay RautVijay Raut

I think there is problem with your SOQL query, return type. You are querying CaseComment object and assigning it to Case object which is not allowed.

 

Try something like following, and i think it would work.

 

for (CaseComment dc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter]) {
LastCaseComment = dc.CommentBody;
}

 

Cheers,

V.R.

 

TraceyTracey
I'm using the Case object in this example
TraceyTracey

Sorry, I meant that I'm not using the Case object. I'm only using the CaseComment object at this point

TraceyTracey

This works

 

trigger UpdateCaseCom on Task (after insert) {

String LastCaseComment;
Datetime DateFilter = Datetime.now().addSeconds(30);

for (CaseComment cc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter])
{
    LastCaseComment = cc.CommentBody;
    
}