Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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 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**.
                            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 (before insert)
{    
    List<Case> cases = new List<Case>();
    for (Integer i = 0; i < Trigger.new.size(); i++ )
    {          
        try
        {
            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;           
            cases.add(c);            
        }
       catch(exception e)
       {
            System.debug('***********'+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  kvat@symetrixsolutions.com        Team1
Rule 2 : Case: To Address  equals  hyvee@symetrixsolutions.com       Team2

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

share|improve this question

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;

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_dmloptions.htm#assignmentruleheader

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.