You need to sign in to do that
Don't have an account?
Robert Wambold 10
CaseComment Trigger generates email with previous Comment instead of Current.
Happy Holidays!
I created a CaseComment Trigger to send an email to the Case Owner when a new CaseComment has been added.
I created a custom field Case_Community_Comment__c on the Case object to hold the most recent CaseComment and utilize a workflow rule to keep it current.
My issue is... my trigger program sends the email before Case_Community_Comment__c has been updated with the most recent CaseComment.
Anyone willing to take look?
Thanks.
Robert
trigger SendCaseCommentEmail on CaseComment (after update) { { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); for(Casecomment cc: Trigger.new) { case cs=new case(id=cc.ParentId); contact co=new contact(id=cs.ContactId); user us=new user(id=cs.OwnerId); //if(us.ProfileId == '00e0y000001jD95') // Almac Community Login User if(cc.IsPublished == True){ // Messaging.SingleEmailMessage message1 = new Messaging.SingleEmailMessage(); mail.setSubject(cs.Subject); mail.setToAddresses(new list<string>{'Robert.Wambold@AlmacGroup.com'}); // CaseOwner Email Address //mail.setToAddresses(new list<string>{us.Email}); // send email to Case Owner mail.settemplateid('00Xc0000000Nimi'); mail.setTargetObjectId('003c000001Mz1vOAAR'); // ContactId mail.whatid= cs.id; // mailmsglist.add(message1); } } // Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> (mailmsglist); // Messaging.SendEmailResult[] results = Messaging.sendEmail(messages); Messaging.SendEmailResult[] results = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail}); if(results.size()>0){ if (results[0].success) { System.debug('The email was sent successfully.'); } else { System.debug('The email failed to send: ' + results[0].errors[0].message); } } } }
Solved...the order of execution was the culprit. The Trigger fires before my WorkFlow, thus making the current CaseComment unavailable.
Th solution was to move the update to case to the Trigger.
All Answers
Solved...the order of execution was the culprit. The Trigger fires before my WorkFlow, thus making the current CaseComment unavailable.
Th solution was to move the update to case to the Trigger.