You need to sign in to do that
Don't have an account?

EmailMessage Trigger not updating Case
Hi all,
I'm building an EmailMessage Trigger that is supposed to identify a case that was created by Email-To-Case feature and update a custom field called SuppliedToEmail__c with the ToAddress of the Email that has been invoked in this trigger.
My After Update is below:
trigger EmailMessageAfterUpdate on EmailMessage (After update) {
for (EmailMessage newEmail : trigger.new){
System.debug('******Entering EmailAfterUpdate******');
if(Trigger.oldMap.get(newEmail.id).ParentId == null && newEmail.ParentId != null){
Case c = [SELECT id, SuppliedToEmail__c FROM Case WHERE Id = :newEmail.ParentId];
System.debug('******Entering EmailAfterUpdate\n'+c.CaseNumber+'******');
c.SuppliedToEmail__c = newEmail.ToAddress;
update c;
System.debug('******Entering EmailAfterUpdate\n'+c.SuppliedToEmail__c+'******');
}
}
}
Unfortunately this trigger is not being invoked, I confirmed by ranning some tests and reviewing the debug logs.
I want to replicate the WebEmail (SuppliedEmail) field update, upon creation of a Email-to-Case record, to perform the same thing with my custom email field.
Your help is appreciated.
The code below works for me:
of course, you will just have to adjust it to fit your scenario... my code was just a test to see if it worked.
All Answers
The code below works for me:
of course, you will just have to adjust it to fit your scenario... my code was just a test to see if it worked.
Below code works well Victor.
Thanks for your input.
I should have also noted that I did not bulkify that code, so you should make sure to do that too.
Glad i could help!