function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TraceyTracey 

Error: Compile Error: Variable does not exist

Could somebody please explain to me why I'm getting this error? I want to extract the Comment from the CaseComment entity if was just recently added to the ase

 

 
Error: Compile Error: Variable does not exist: cc.CommentBody at line 9 column 23 

 

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;

     }

    for (Task t : [select Description, Type, Subject, isclosed, status, WhatId from task where Id in :Trigger.new]) {

SuperfellSuperfell
You have a semi-colon on the end of your for line, this means the code you think is inside the for loop is not, and so now the cc variable is out of scope.
TraceyTracey

Hi Simon

 

Thanks for that but now I getting a new 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;

}

Vijay RautVijay Raut
Replied to your other thread.