You need to sign in to do that
Don't have an account?
WrogWrog
Can I update the EmailMessage status in an apex trigger?
Still a newbie to Apex (in fact, a newbie to "proper" code writing at all). Can't see a simple answer to my question, so here goes with a discussion topic.
We would like to set the status of any "new" (unread) emails attached to a case to "read" at the point of closing a case. Can I actually do this?
My current trigger is as below. If I understand the log, it fails (with an unknown error) at the line highlighted in red. Is this because I can't do that, or becuase I'm doing it wrong?
I've been told I should be able to change the status of an email remotely, but I could imagine this might not be "good practice".
Roger England
Code:
trigger Case_CloseEmailComment_update on Case (before update) { Case[] cs = Trigger.new; if (cs[0].Status == 'Closed' ) { ID csId = cs[0].Id; if (cs.size() > 0){ cs[0].HasCommentsUnreadByOwner = false; EmailMessage[] ems = [select Id, Status from EmailMessage where (ParentId = :csId)]; if (ems.size() > 0){ for (EmailMessage em: ems){ if (em.Status == '0'){ em.Status = '1'; update em; } } } } } }
I am having the same problem, everytime I want to update the status I get un unexpected error. Did you find the answer?
I think I know why.. Email Message is not editable so you can't update it.
I am right?