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
TilluTillu 

How to write validation Rule for this?

I want to write validation Rule for case comments. SO if any users wants to delete/update  the case comments then it wont allowed deletion or modification. But i saw that there is no field like comments in the case fields. Then how could i acheive this ?


User-added image
Best Answer chosen by Tillu
Anurag JainAnurag Jain
Hi Tillu,

Please write following code on Setup>Customize>Cases>Case Comments then Trigger path.
  • trigger validation on CaseComment (before update, before delete) {  
  •     if(Trigger.isUpdate){
  •         for(CaseComment caseCmt : Trigger.new){       
  •             caseCmt.addError('You can not Update Case Comment.');
  •         }
  •     }
  •     else{
  •         for(CaseComment caseCmt : Trigger.old){       
  •             caseCmt.addError('You can not Delete Case Comment.');
  •         }
  •        
  •     }
  • }

Hope its solves you problem... :)
Thanks.
Anurag

All Answers

Anurag JainAnurag Jain

HI Tillu,

"Case Comment" is child object of Case,
i think we cannot write Validation rule for Case Comment but we can write Triiger for your Requirment.

Thanks
Anurag

Anurag JainAnurag Jain
You Should write trigger on Case Comment under Setup>Customize>Cases>Case Comments then Trigger,
and events should be before Update and before delete.

Hope it helps...;)
TilluTillu
Can you give me sample code  when  user update /delete  then we display some error msg
Anurag JainAnurag Jain
Hi Tillu,

Please write following code on Setup>Customize>Cases>Case Comments then Trigger path.
  • trigger validation on CaseComment (before update, before delete) {  
  •     if(Trigger.isUpdate){
  •         for(CaseComment caseCmt : Trigger.new){       
  •             caseCmt.addError('You can not Update Case Comment.');
  •         }
  •     }
  •     else{
  •         for(CaseComment caseCmt : Trigger.old){       
  •             caseCmt.addError('You can not Delete Case Comment.');
  •         }
  •        
  •     }
  • }

Hope its solves you problem... :)
Thanks.
Anurag
This was selected as the best answer
Troy TurleyTroy Turley
hello. Thank you for the code. It works for all users. In cases when the trigger should execute allowing one or two users to update or delete comments, how would the code look?