Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.29 KB | None | 0 0
  1. public void updateLastActivityDate(){
  2.  
  3. Map<Id, Application__c> applicationMap = new Map<Id, Application__c>();
  4.  
  5. if (Trigger.isAfter && (Trigger.isUpdate)){
  6. System.debug(LoggingLevel.INFO, 'Test 1');
  7. for (Application__c application : (List<Application__c>) Trigger.new){
  8. System.debug(LoggingLevel.INFO, application);
  9. System.debug(LoggingLevel.INFO, 'Test 1.1');
  10. if (Utils.isFieldChanging('Follow_Up_Date__c', application, Trigger.oldMap)){
  11. System.debug(LoggingLevel.INFO, 'Test 1.2');
  12. applicationMap.put(application.Id, application);
  13. System.debug(LoggingLevel.INFO, applicationMap);
  14. }
  15. }
  16. }
  17.  
  18.  
  19.  
  20. System.debug(LoggingLevel.INFO, 'Task 1.3');
  21. if (applicationMap.size() > 0){
  22.  
  23. System.debug(LoggingLevel.INFO, 'Task 1.4');
  24. List<Task> tasks = [SELECT Id, CreatedDate, WhatId FROM Task WHERE WhatId IN :applicationMap.keySet() AND CreatedDate = TODAY];
  25.  
  26. List<Application__c> applicationsToUpdate = new List<Application__c>();
  27. System.debug(LoggingLevel.INFO, 'Task 1.5');
  28. if (tasks.isEmpty()){
  29. for (Application__c application : (List<Application__c>) Trigger.new){
  30. System.debug(LoggingLevel.INFO, 'Test error message');
  31. application.addError('An activity must be logged today to change the Follow-Up Date');
  32. }
  33. System.debug(LoggingLevel.INFO, 'Test 1.6');
  34. if (tasks.size() > 0){
  35. for (Id applicationId : applicationMap.keySet()){
  36. Application__c app = applicationMap.get(applicationId);
  37. if (app != null){
  38. Application__c a = new Application__c(
  39. Id=applicationId,
  40. Last_Activity_Date__c = System.TODAY()
  41. );
  42. applicationsToUpdate.add(a);
  43. System.debug(LoggingLevel.INFO, applicationsToUpdate);
  44. }
  45. }
  46.  
  47. if (applicationsToUpdate.size() > 0){
  48. update applicationsToUpdate;
  49. System.debug(LoggingLevel.INFO, applicationsToUpdate);
  50. }
  51. }
  52. }
  53. }
  54. }
  55.  
  56. static testMethod void updateLastActivityDate(){
  57. //CaseShareDelete.doChainJob = false;
  58. TestFuel fuel = new TestFuel();
  59. Utils u = new Utils();
  60.  
  61. User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
  62.  
  63. Profile p = [SELECT Id, Name FROM Profile WHERE Name = 'WV Operations Users'];
  64. User u1 = fuel.newOperationsUser();
  65. insert u1;
  66.  
  67. System.runAs(u1){
  68. Account account = fuel.newAccount();
  69. Account carrier = fuel.newCarrierAccount();
  70. Account brokerDealer = fuel.newBrokerDealerAccount();
  71. insert new List<Account>{account, carrier, brokerDealer};
  72.  
  73. Contract contract = fuel.newContract();
  74. contract.RecordTypeId = '01236000000SBRzAAO';
  75. contract.AccountId = account.Id;
  76. contract.Status = 'Draft';
  77. insert contract;
  78.  
  79. Territory__c territory = fuel.newTerritory();
  80. insert territory;
  81.  
  82. Contact contact = fuel.newContact();
  83. contact.RecordTypeId = '012360000008QLxAAM';
  84. contact.AccountId = account.Id;
  85. contact.Broker_Dealer__c = brokerDealer.Id;
  86. contact.Wealthvest_Producer_ID__c = contract.Id;
  87. contact.Contact_Stage__c = '6 - Contracted Producer';
  88. contact.Territory__c = territory.Id;
  89. insert contact;
  90.  
  91. Appointment__c appointment = fuel.newCarrierAppointment();
  92. appointment.Producer_Contact__c = contact.Id;
  93. appointment.Carrier__c = carrier.Id;
  94. appointment.WV_Producer_Contract__c = contract.Id;
  95. //appointment.Status__c = null;
  96. appointment.Carrier_Appointment_Stage__c = '4-Pending with Carrier';
  97. insert appointment;
  98.  
  99. CarrierLine__c carrierLine = fuel.newCarrierLine();
  100. carrierLine.Carrier__c = carrier.Id;
  101. insert carrierLine;
  102.  
  103. CarrierLineProduct__c product = fuel.newProduct();
  104. product.Carrier__c = carrier.Id;
  105. product.CarrierLine__c = carrierLine.Id;
  106. insert product;
  107.  
  108. Application__c application = fuel.newApplication();
  109. application.RecordTypeId = '01236000000SKvhAAG';
  110. application.Policy_Number__c = 'W92745100';
  111. application.Tax_Status__c = 'Qualified';
  112. application.Gender__c = 'Male';
  113. application.Age__c = 43;
  114. application.Application_Stage__c = '00 - WV Preliminary App Review';
  115. application.Status__c = 'Reviewed by WV, App Not Submitted to Carrier';
  116. application.Investor__c = 'Sam Test';
  117. application.Carrier__c = carrier.Id;
  118. application.Product_Carrier__c = product.Id;
  119. application.Submitted_Premium__c = 100000;
  120. application.Sign_Date__c = System.today() - 7;
  121. application.Signed_State__c = 'CA';
  122. application.Application_Sent_To__c = 'WealthVest';
  123. application.Issue_Status_Only__c = 'Full Case Management';
  124. application.DOB__c = Date.newInstance(1975, 12, 9);
  125. application.Received_Date__c = System.today() - 2;
  126. application.Submitted__c = System.today();
  127. application.Submitted_Premium__c = 100000;
  128. application.Investor_SSN__c = '756342132';
  129. application.Carrier_Appointment__c = appointment.Id;
  130. insert application;
  131.  
  132. Application_Line_Item__c ali = fuel.newApplicationLine();
  133. ali.Application__c = application.Id;
  134. insert ali;
  135.  
  136. Producer_Application_Line_Item__c pali = fuel.newProducerApplicationLineItem();
  137. pali.Application_Line_Item__c = ali.Id;
  138. pali.Producer__c = contact.Id;
  139. pali.Split_pct__c = 100.00;
  140. insert pali;
  141.  
  142. List<Application__c> applicationList = [SELECT Id FROM Application__c WHERE Id = :application.Id];
  143. System.assertEquals(1, applicationList.size());
  144.  
  145. Test.startTest();
  146.  
  147. List<Task> taskList = [SELECT Id, WhatId, CreatedDate FROM Task WHERE WhatId = :application.Id];
  148. System.assertEquals(true, taskList.isEmpty());
  149.  
  150. try{
  151. application.Follow_Up_Date__c = System.today() + 2;
  152. update application;
  153. } catch(Exception e) {
  154. System.Assert(e.getMessage().contains('An activity must be logged today to change the Follow-Up Date'));
  155. }
  156.  
  157. applicationList = [SELECT Id, Follow_Up_Date__c, Last_Activity_Date__c FROM Application__c WHERE Id = :application.Id];
  158. System.assertEquals(null, applicationList[0].Last_Activity_Date__c);
  159. System.assertNotEquals(System.today(), applicationList[0].Follow_Up_Date__c);
  160.  
  161. Task task = new Task();
  162. task.recordTypeId = '01236000000OkDPAA0';
  163. task.ActivityDate = System.today();
  164. task.WhatId = application.Id;
  165. task.Type = 'OutBound Phone Call';
  166. task.Subject = 'Call';
  167. task.Status = 'Completed';
  168. task.CreatedDate = System.now() -1;
  169. task.LastModifiedDate = System.now() -1;
  170. Task task2 = new Task();
  171. task2.recordTypeId = '01236000000OkDPAA0';
  172. task2.ActivityDate = System.today() + 2;
  173. task2.WhatId = application.Id;
  174. task2.Type = 'Email';
  175. task2.Subject = 'Email';
  176. task2.Status = 'Completed';
  177. task2.CreatedDate = System.now();
  178. task2.LastModifiedDate = System.now();
  179. insert new List<Task>{task, task2};
  180.  
  181. taskList = [SELECT Id, WhatId, CreatedDate FROM Task WHERE WhatId = :application.Id];
  182. System.assertEquals(2, taskList.size());
  183.  
  184. application.Follow_Up_Date__c = System.today();
  185. update application;
  186.  
  187. applicationList = [SELECT Id, Follow_Up_Date__c, Last_Activity_Date__c FROM Application__c WHERE Id = :application.Id];
  188. System.assertEquals(System.today(), applicationList[0].Last_Activity_Date__c);
  189. System.assertEquals(System.today(), applicationList[0].Follow_Up_Date__c);
  190. Test.stopTest();
  191. }
  192. }
  193.  
  194. if (Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert)){
  195. if (ApplicationHandler.firstRun){
  196. handler.firstApplicationRun();
  197. handler.updateLastActivityDate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement