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 < Trigger.new.size(); i++ )
            Case c = new Case();
            c=[SELECT id, Description, caseNumber FROM Case WHERE Id = :Trigger.new[i].ParentId];           
            c.To_Address__c= Trigger.new[i].ToAddress;           
       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  [email protected]        Team1
Rule 2 : Case: To Address  equals  [email protected]       Team2

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

2 Answers 2


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;



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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .