+ Start a Discussion
RomyRomy 

Trigger for bulk case update

I an new to salesforce and using Email to case to register new cases. Once the case is registered it moves from one department to another before it is closed. This is done by changing the Lookup field Department__c (Lookup to custom object Department__c) on Case. Each time dept is changed, a record is inserted in the Dept_move__c custome object Which is detail with Case as master. When the case is closed, it is assigned a new page layout -- Closed Case Page Layout that has no Close Case Button and also email is sent to the customer with case details. If customer feels that the problem is still pending, he can reply to that and it will automatically reopen the case. I have already implemented this functionality through after update trigger on Case.

 

It work fine with single case update but I need to modify it so that it can work for multiple or bulk case updates. Can anyone suggest me what point i should consider while updating the trigger for handling bulk cases:

 

Message Edited by Romy on 02-14-2010 05:22 PM
Best Answer chosen by Admin (Salesforce Developers) 
werewolfwerewolf

Ah, no, you can't insert with workflow.

 

See all those places where you reference trigger.new[0]?  That's your problem.  You're only touching the first case on the list.  You should be doing most of that in a for loop (except for queries, inserts and updates, which you should do outside the loop).

All Answers

werewolfwerewolf
As far as I can tell you do not need to write a trigger at all for this, it could have been accomplished with a simple workflow.  See my response to your other, similar post.
RomyRomy
But, I am inserting new record to the Department_c (detail object with case as master) everytime the Dept_move__c field (Lookup to Department__c Object) on case is updated. Is it possible to insert these new records through workflow?
Message Edited by Romy on 02-14-2010 05:24 PM
werewolfwerewolf

Ah, no, you can't insert with workflow.

 

See all those places where you reference trigger.new[0]?  That's your problem.  You're only touching the first case on the list.  You should be doing most of that in a for loop (except for queries, inserts and updates, which you should do outside the loop).

This was selected as the best answer