Guest User

Untitled

a guest
Feb 27th, 2019
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. trigger CaseTrigger on Case (before insert,before update, after update)
  2. {
  3. if((Trigger.isBefore && Trigger.isUpdate)||(Trigger.isBefore && Trigger.isInsert))
  4. {
  5.  
  6. List<Id> contactIds = new List<Id>();
  7. List<Id> acctIds = new List<Id>();
  8. for (Case c: Trigger.new){
  9. if (c.EntitlementId == null && c.ContactId!= null && c.AccountId!= null){
  10. contactIds.add(c.ContactId);
  11. acctIds.add(c.AccountId);
  12. }
  13. }
  14. if(contactIds.isEmpty()==false || acctIds.isEmpty()==false){
  15. /* Added check for active entitlement */
  16. List <EntitlementContact> entlContacts = [Select e.EntitlementId,e.ContactId,e.Entitlement.AssetId From EntitlementContact e
  17. Where e.ContactId in:contactIds
  18. And e.Entitlement.EndDate >= Today And e.Entitlement.StartDate <= Today];
  19. if(entlContacts.isEmpty()==false){
  20. for(Case c: Trigger.new){
  21. if(c.EntitlementId == null && c.ContactId!= null){
  22. for(EntitlementContact ec:entlContacts){
  23. if(ec.ContactId==c.ContactId){
  24. c.EntitlementId = ec.EntitlementId;
  25. if(c.AssetId==null && ec.Entitlement.AssetId!=null)
  26. c.AssetId=ec.Entitlement.AssetId;
  27. break;
  28. }
  29. } // end for entitlement
  30. }
  31. } // end for case
  32. } else{
  33. List <Entitlement> entls = [Select e.StartDate, e.Id, e.EndDate, e.AccountId, e.AssetId
  34. From Entitlement e
  35. Where e.AccountId in:acctIds And e.EndDate >= Today And e.StartDate <= Today];
  36. if(entls.isEmpty()==false){
  37. for(Case c: Trigger.new){
  38. if(c.EntitlementId == null && c.AccountId!= null){
  39. for(Entitlement e:entls){
  40. if(e.AccountId==c.AccountId){
  41. c.EntitlementId = e.Id;
  42. if(c.AssetId==null && e.AssetId!=null)
  43. c.AssetId=e.AssetId;
  44. break;
  45. }
  46. } // end for
  47. }
  48. } // end for
  49. }
  50. }
  51. } // end if(contactIds.isEmpty()==false)
  52.  
  53. }
  54.  
  55.  
  56. if(Trigger.isBefore && Trigger.isUpdate)
  57. {
  58. System.debug('entered if condition');
  59.  
  60. for(Case c : Trigger.new)
  61. {
  62. if (c.Assignment_Group__c != trigger.oldMap.get(c.Id).Assignment_Group__c){
  63. System.debug('Updating logic');
  64. List<Group> qid = [select Id from Group where Name = : c.Assignment_Group__c and Type = 'Queue'];
  65. for(Group g : qid)
  66. {
  67. c.OwnerId = g.id;
  68. System.debug('updated');
  69. }
  70. }}
  71. }
  72.  
  73. if(Trigger.isBefore && Trigger.isUpdate)
  74. {
  75. for(Case c : Trigger.new)
  76. {
  77. 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')
  78. {
  79. c.Group_Manager_Email__c = 'sargware@gmail.com'; c.Escalation_Level_2_Email__c ='sargware@gmail.com'; c.Escalation_Level_3_Email__c='sargware@gmail.com';
  80. }
  81. }
  82. }
  83.  
  84. if(Trigger.isBefore && Trigger.isUpdate)
  85. {
  86. for(Case c : Trigger.new)
  87. {
  88. if(c.Internal_Impact__c == 'Low' && c.Internal_Urgency__c=='Low')
  89. {
  90. c.Priority='Planning';
  91. }
  92. if(c.Internal_Impact__c == 'High' && c.Internal_Urgency__c=='High')
  93. {
  94. c.Priority='Critical';
  95. }
  96. if(c.Status=='Pending User' || c.Status=='Pending Vendor')
  97. {
  98. c.IsStopped = True;
  99. }
  100.  
  101. }
  102.  
  103. }
  104.  
  105. if((Trigger.isAfter && Trigger.isUpdate))
  106. {
  107. Set<Id> Ids = new Set<Id>();
  108. Set<Id> IdR = new Set<Id>();
  109. Set<Id> IdC = new Set<Id>();
  110. List<SC_Problem_Case_Link__c> scprblm = new List<SC_Problem_Case_Link__c>();
  111. List<SC_Problem_Case_Link__c> scprblmo = new List<SC_Problem_Case_Link__c>();
  112. List<SC_Problem_Case_Link__c> scprblmc = new List<SC_Problem_Case_Link__c>();
  113. for (Case cs: Trigger.new)
  114. {
  115. Case oldLead = Trigger.oldMap.get(cs.Id);
  116.  
  117. if (cs.Status == 'Tested' && Trigger.oldMap.get(oldLead .Id).Status=='Ready for Testing')
  118. {
  119. Ids.add(cs.Id);
  120. }
  121. if (cs.Status == 'ReOpen')
  122. {
  123. IdR.add(cs.Id);
  124. }
  125. if (cs.Status == 'Closed')
  126. {
  127. IdC.add(cs.Id);
  128. }
  129. }
  130.  
  131. for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Ready for Testing' AND Case__c in :Ids])
  132. {
  133.  
  134. if (rateSheet.Status__c != 'Tested') {
  135. rateSheet.Status__c = 'Tested';
  136. //rateSheet.Case__c.Status= 'Awaiting Deployment';
  137. scprblm.add(rateSheet);
  138. }
  139.  
  140. }
  141. if (!scprblm.isEmpty()) {
  142. update scprblm;
  143. }
  144.  
  145.  
  146. for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdR])
  147. {
  148. // List<SC_Problem_Case_Link__c> accts = [Select Id, Status__c from SC_Problem_Case_Link__c where Id in : Trigger.old];
  149.  
  150. if (rateSheet.Status__c != 'Open') {
  151. rateSheet.Status__c = 'Open';
  152. scprblmo.add(rateSheet);
  153. }
  154.  
  155. }
  156. if (!scprblmo.isEmpty()) {
  157. update scprblmo;
  158. }
  159.  
  160.  
  161. for (SC_Problem_Case_Link__c rateSheet: [select Id,Status__c from SC_Problem_Case_Link__c where Status__c = 'Resolved' AND Case__c in :IdC])
  162. {
  163.  
  164. if (rateSheet.Status__c != 'Closed') {
  165. rateSheet.Status__c = 'Closed';
  166. scprblmc.add(rateSheet);
  167. }
  168.  
  169. }
  170. if (!scprblmc.isEmpty()) {
  171. update scprblmc;
  172. }
  173. }
  174. }
Add Comment
Please, Sign In to add comment