You need to sign in to do that
Don't have an account?
Tej
Case field Update based on attached emailmessage status
I created a trigger to update a field in Case to either New or Read based on attached emailmessages status.
if there are any new emails attached to case, the case email status should be "new".
If there are no New emails the case email status should be "Read".
everything is working fine except, the trigger is not getting fired when they open the new email to read, the emailmessage status is getting updated from New to Read, but the trigger is not getting fired to update the case email status.
please check the below code.
trigger CaseEmailStatusUpdate on EmailMessage (after insert, after update) { ID caseId; list<EmailMessage> emails = new list<EmailMessage>(); set<string> status = new set<String>(); Case c = new Case(); for( EmailMessage e : trigger.new){ caseId = e.ParentId; } emails = [ SELECT Id, ParentId, Status, Subject FROM EmailMessage where parentId = :caseId]; c = [ Select Id, Case_Email_Status__c From Case where Id = :caseId]; for( EmailMessage e : emails){ status.add(e.Status); } if(status.size() > 0 && status.Contains('0')){ c.Case_Email_Status__c = 'New'; }else if (status.size() > 0 && !status.Contains('0')){ c.Case_Email_Status__c = 'Read'; } update c; }
try this.
the trigger will never get invoked in my case because, per SFDC support email status change from New to Read is not a DML operation, its salesforce standard functionality, therefore it can't invoke a trigger or wrkflow.