You need to sign in to do that
Don't have an account?
APEX Trigger on Email Message causing a problem in Case Assignment Rules
Hi All,
We have a after insert trigger on EmailMessage object to Capture "To Email address" (routing address) in Email To Case(We have 10 routing address).
Whenever a Case gets created from Email to Case, in case history it shows like this.
10/3/2012 11:28 AM Surander Changed Owner (Assignment) from Gallucci to Team1.
Changed Owner (Assignment) from Surander to Galluci.
Created.
But Surander is the Automated Case User, Gallucci is the Default owner of a case when assignment rules fail to locate an owner and Team1 is Queue.
But ideally it should not Change the Owner to Gallucci (If assignment rules locates an Owner for Case).
If i inactive the trigger it is working fine, and Case history shows like this.
10/3/2012 11:28 AM Surander Changed Owner (Assignment) from Surander to Team1.
Created.
I need to write a workflow, when ever case owner is Gallucci, but for each and every Case workflow is firing because of the above issue.
Trigger Code:
trigger ToAddress on EmailMessage (after insert) { List<Case> cases = new List<Case>(); for (Integer i = 0; i < Trigger.new.size(); i++ ) { try { EmailMessage newEmail = Trigger.new[i]; List<Case> c = [SELECT id, Description, caseNumber FROM Case WHERE Id = :newEmail.ParentId]; if (c.size() > 0 ){ c[0].To_Address__c= newEmail.ToAddress; update c; } } catch(exception e) { System.debug('***********'+e); } } update cases; }
Please reply with any coding or configuration that will help in this regard.
Any help is much appreciated.
Regards,
Susheel Reddy
Can we get a look at assignment rules you have configured ?
We have assignment rules based upon To Email address. These email addresses are updated by the trigger.
Thanks for your reply, but still it shows the same and Workflow is firing.
Is there a Trigger on Cases before or after which might be resetting the value and may be put the debug logs and check.
Logically it should have worked as Workflows would run after assignment rules.
We don't have any triggers on Cases, but we have two triggers on Attachmnets object.
I will try with adding some dubug logs.
Again thanks so much.
Hi Susheel,
When you get an opportunity, please try the below code and let me know if it works.
Thanks,
Praveen K.