Guest User

Untitled

a guest
Jan 27th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. trigger caseOwnerUpdate on Case (before insert,before update,after update)
  2.  
  3. if(Trigger.isBefore && Trigger.isUpdate)
  4. {
  5. System.debug('entered if condition');
  6.  
  7. for(Case c : Trigger.new)
  8. {
  9.  
  10. System.debug('Updating logic');
  11. List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
  12. for(Group g : qid)
  13. {
  14. c.OwnerId = g.id;
  15. System.debug('updated');
  16. }
  17. }
  18. }
  19.  
  20. List<Case> updateCS = new List<Case>();
  21. Map<Id,Case> cases = new Map<Id,Case>();
  22.  
  23. for (Case cs : Trigger.new)
  24. {
  25. if(Trigger.isUpdate) {
  26. System.debug('>>>>> Owner ID: '+cs.ownerId+' Temp Owner ID: '+cs.TempOwnerId__c);
  27. if(cs.TempOwnerId__c <> null && cs.TempOwnerId__c <> '') {
  28. if(cs.OwnerId <> cs.TempOwnerId__c) {
  29. cases.put(cs.id,cs);
  30. }
  31. }
  32. }
  33. }
  34. if (cases.isEmpty()) return;
  35.  
  36. for (Case cs : [SELECT OwnerId,TempOwnerId__c FROM Case WHERE id in :cases.keySet()]) {
  37. cs.OwnerId = cases.get(cs.Id).TempOwnerId__c;
  38. cs.TempOwnerId__c = 'SKIP'; //flag to stop infinite loop upon update
  39. updateCS.add(cs);
  40. }
  41. System.debug('>>>>>Update Cases: '+updateCS);
  42.  
  43. //
  44. //Update last assignment for Assignment Group in batch
  45. //
  46. if (updateCS.size()>0) {
  47. try {
  48. update updateCS;
  49. } catch (Exception e){
  50.  
  51. }
  52. }
  53.  
  54. }
  55.  
  56. if(Trigger.isBefore && Trigger.isUpdate)
  57. {
  58. for(Case c : Trigger.new)
  59. {
  60. if(c.Assignment_Group__c=='Tech Support'||c.Assignment_Group__c=='GD-IT'||c.Assignment_Group__c=='App-Support'||c.Assignment_Group__c=='GD-RM'||c.Assignment_Group__c=='GD-DB'||c.Assignment_Group__c=='Dev-Ops'||c.Assignment_Group__c=='App-Management'||c.Assignment_Group__c=='PDT-DS-Engg'||c.Assignment_Group__c=='PDT-US-Engg')
  61. {
  62. c.Group_Manager_Email__c = 'sgaware148@gmail.com'; c.Escalation_Level_2_Email__c ='sgaware148@gmail.com'; c.Escalation_Level_3_Email__c='sgaware148@gmail.com';
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment