You need to sign in to do that
Don't have an account?
SF_Admin96
APEX Code Help: Multiple entries in Case Comment when clicking Edit and Save.
Hi All,
I currently implemented a code (which I copied somewhere) in my Production which copies the email body and insert it to Case Comment. However, I am getting multiple entries when I edit and Save the record.
Ex. When the email comes in, it copy the email body and the code insert it to case comment. When I click the Edit button and Save WITHOUT changing any information, it creates a duplicate on the case comment.
How can I correct this behavior that it should only create case comment when a new email is sent or received?
Any assistance is greatly appreciated.
I currently implemented a code (which I copied somewhere) in my Production which copies the email body and insert it to Case Comment. However, I am getting multiple entries when I edit and Save the record.
Ex. When the email comes in, it copy the email body and the code insert it to case comment. When I click the Edit button and Save WITHOUT changing any information, it creates a duplicate on the case comment.
How can I correct this behavior that it should only create case comment when a new email is sent or received?
trigger commentMove on Case (after update) { Case myCase = trigger.new[0]; if (myCase.New_Case_Comment__c!= null) { String caseId= myCase.ID; CaseComment cc = new CaseComment(CommentBody=myCase.New_Case_Comment__c,parentID=caseId); insert cc; } }
Any assistance is greatly appreciated.
Something like
Please note this trigger is not bulk safe, since you are just picking up only first record from trigger.new
I will definitely try this one out. I have one question though, what are the cons if the trigger is not bulk safe?