I'm facing a problem when I try to implement a functionality that lets users see if there is a unread Email on a Case, indicated by an icon in a formula field. I have a workflow rule that adds the icon when an email is received on a Case, by setting a checkbox the following rule criteria was fullfilled on the EmailMessage object:
(Email Message: Is Incoming equals True) and (Email Message: Status equals New)
In the formula field checking the checkbox value and set the appropirate icon, this works fine. The checkbox is set and the icon is added. But when I try to remove the icon when the Email's status changes from New to Read I could not get my other workflow rule to fire, also on the EmailMessage object with the following rule criteria:
(Email Message: Is Incoming equals True) and (Email Message: Status not equals New)
I could not see anything indicating that i had fired in my debug logs. So I started writing a Trigger that were supposed to set the checkbox to False (onBeforeInsert and onBeforeUpdate):
Set<ID> caseIds = new Set<ID>();
for(EmailMessage message : newList){
if(message.Incoming == true && message.Status == 'Read'){
caseIds.add(message.parentId);
}
}
List<Case> csUpdateList = [select id, New_Email__c from Case where id IN :caseIds];
for(Case c : csUpdateList)
c.New_Email__c = false;
update csUpdateList;
This still doesn't solve the problem and nothing is shown in my debug logs, I'am obviously missing something but I cannot figure out what. What is the best way to recognice that an Email has been read (opened)? I assume it is checking the Status, and if so, what is the best way to "catch" this event? If I could solve this with workflows I would prefer it, but any help with the Trigger is highly appreciated.
Ciao!