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
Glen.ax1034Glen.ax1034 

get casecomments from case

I can't figure out why this isn't triggering when i have it run against a case that has comments.

 

usually i'd expect it to throw an error. but the lack of error shows that it isn't even entering the for loop

 

for (Case escalatedcase:Trigger.new){
    
    
   // escalatedcase.addError(escalatedcase.CaseComments);
    
    
                                        for(CaseComment oldcomment :  escalatedcase.CaseComments) {
                                      CaseComment newcomment = oldcomment.clone(false, true);
                                      //newcomment.ParentId = CaseAdd.Id;
                                      
                                      ccomments.add(newcomment);
                                       escalatedcase.addError('Please choose a Tier 2 Escalation Level to direct escalation.'); //in your face!
                                    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
dmchengdmcheng

Data for related records (CaseComments) is not automatically available in a trigger on the parent object (Case).  You need to retrieve the related records with a SOQL query in order to work with them in the trigger.

All Answers

AmitSahuAmitSahu

Is it a after update /before update trigger on the Case ? and did you check whether the case comment is being captured at this point ?

Glen.ax1034Glen.ax1034

here

 

trigger EscalateCase on Case (before update, before insert) {

 I could give you all of the code but i dont want to start confusing you. there's a lot of code.

 

here's a screenshot of the case that i am using to debug:

 

dmchengdmcheng

Data for related records (CaseComments) is not automatically available in a trigger on the parent object (Case).  You need to retrieve the related records with a SOQL query in order to work with them in the trigger.

This was selected as the best answer