Find your content:

Search form

You are here

After Insert Trigger on Email Message causing a problem in Case Assignment Rules


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**.

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 inactivate 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**.

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 (before insert)
    List<Case> cases = new List<Case>();
    for (Integer i = 0; i <; i++ )
            Case c = new Case();
            c=[SELECT id, Description, caseNumber FROM Case WHERE Id =[i].ParentId];           
       catch(exception e)
    update cases;

We have assignment rules based upon To Email address. These email addresses are updated by the trigger.

Rule 1 : Case: To Address  equals        Team1
Rule 2 : Case: To Address  equals       Team2

Please reply with any coding or configuration that will help in this regard.Any help is much appreciated.

Attribution to: Susheel Reddy

Possible Suggestion/Solution #1

I would reckon you need to specify the assignment rule to use use the Database.DMLOptions

Database.DMLOptions dmo = new Database.DMLOptions(); dmo.assignmentRuleHeader.useDefaultRule= true;

Attribution to: techtrekker

Possible Suggestion/Solution #2

Whenever the case is created through API the assignment rule dont run unless you instantiate DML options and set it .You may need to do it before you insert the case.

Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content