+ Start a Discussion
MatsMats 

Case assignment rules don't get executed when running trigger on attachment

I have written a couple of Apex triggers that fire Before Insert on the case and that does sucessfully trigger the assigment rules. Everything is fine.

 

Now I added a trigger that fires when a user adds an attachment to a case. The trigger successfully updates the case status as intended but the case assigment rules are not invoked. Drat!

 

trigger NewAttachment on Attachment (after insert) {
        List<Case> CasesToUpdate = new List<Case>();
            for (Attachment t: Trigger.new){
                try{Case c = new Case(Id = t.ParentId);
                    c.Status='New Case';
                    CasesToUpdate.add(c);
                    }catch (Exception e){
                        }
                        }
                        update CasesToUpdate;
                        }

 

 

 

(I did not write this code myself, only modified it from a post on these forums)

 

As far s I understand, the assignment rules should fire when the cases are updated. But they don't seem to do that.  I have double and triple checked the string 'New Case'

 

Any thoughts?

Best Answer chosen by Mats

All Answers

Mats ErikssonMats Eriksson

My Hero!

 

Thx a lot for your help. Solved the problem nicely.

 

For reference, the code looks like this now:

 

trigger NewAttachment on Attachment (after insert) {
        List<Case> CasesToUpdate = new List<Case>();
            for (Attachment t: Trigger.new){
                try{Case c = new Case(Id = t.ParentId);
                    c.Status='New Case';
                    database.DMLOptions dmo = new database.DMLOptions();
                    dmo.AssignmentRuleHeader.UseDefaultRule= true;
                    c.setOptions(dmo);
                    CasesToUpdate.add(c);
                    }catch (Exception e) {
                        }
                        }
                        update CasesToUpdate;
                        } 

 

Cheers,

 

/Mats