Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void updateLastActivityDate(){
- Map<Id, Application__c> applicationMap = new Map<Id, Application__c>();
- if (Trigger.isAfter && (Trigger.isUpdate)){
- System.debug(LoggingLevel.INFO, 'Test 1');
- for (Application__c application : (List<Application__c>) Trigger.new){
- System.debug(LoggingLevel.INFO, application);
- System.debug(LoggingLevel.INFO, 'Test 1.1');
- if (Utils.isFieldChanging('Follow_Up_Date__c', application, Trigger.oldMap)){
- System.debug(LoggingLevel.INFO, 'Test 1.2');
- applicationMap.put(application.Id, application);
- System.debug(LoggingLevel.INFO, applicationMap);
- }
- }
- }
- System.debug(LoggingLevel.INFO, 'Task 1.3');
- if (applicationMap.size() > 0){
- System.debug(LoggingLevel.INFO, 'Task 1.4');
- List<Task> tasks = [SELECT Id, CreatedDate, WhatId FROM Task WHERE WhatId IN :applicationMap.keySet() AND CreatedDate = TODAY];
- List<Application__c> applicationsToUpdate = new List<Application__c>();
- System.debug(LoggingLevel.INFO, 'Task 1.5');
- if (tasks.isEmpty()){
- for (Application__c application : (List<Application__c>) Trigger.new){
- System.debug(LoggingLevel.INFO, 'Test error message');
- application.addError('An activity must be logged today to change the Follow-Up Date');
- }
- System.debug(LoggingLevel.INFO, 'Test 1.6');
- if (tasks.size() > 0){
- for (Id applicationId : applicationMap.keySet()){
- Application__c app = applicationMap.get(applicationId);
- if (app != null){
- Application__c a = new Application__c(
- Id=applicationId,
- Last_Activity_Date__c = System.TODAY()
- );
- applicationsToUpdate.add(a);
- System.debug(LoggingLevel.INFO, applicationsToUpdate);
- }
- }
- if (applicationsToUpdate.size() > 0){
- update applicationsToUpdate;
- System.debug(LoggingLevel.INFO, applicationsToUpdate);
- }
- }
- }
- }
- }
- static testMethod void updateLastActivityDate(){
- //CaseShareDelete.doChainJob = false;
- TestFuel fuel = new TestFuel();
- Utils u = new Utils();
- User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
- Profile p = [SELECT Id, Name FROM Profile WHERE Name = 'WV Operations Users'];
- User u1 = fuel.newOperationsUser();
- insert u1;
- System.runAs(u1){
- Account account = fuel.newAccount();
- Account carrier = fuel.newCarrierAccount();
- Account brokerDealer = fuel.newBrokerDealerAccount();
- insert new List<Account>{account, carrier, brokerDealer};
- Contract contract = fuel.newContract();
- contract.RecordTypeId = '01236000000SBRzAAO';
- contract.AccountId = account.Id;
- contract.Status = 'Draft';
- insert contract;
- Territory__c territory = fuel.newTerritory();
- insert territory;
- Contact contact = fuel.newContact();
- contact.RecordTypeId = '012360000008QLxAAM';
- contact.AccountId = account.Id;
- contact.Broker_Dealer__c = brokerDealer.Id;
- contact.Wealthvest_Producer_ID__c = contract.Id;
- contact.Contact_Stage__c = '6 - Contracted Producer';
- contact.Territory__c = territory.Id;
- insert contact;
- Appointment__c appointment = fuel.newCarrierAppointment();
- appointment.Producer_Contact__c = contact.Id;
- appointment.Carrier__c = carrier.Id;
- appointment.WV_Producer_Contract__c = contract.Id;
- //appointment.Status__c = null;
- appointment.Carrier_Appointment_Stage__c = '4-Pending with Carrier';
- insert appointment;
- CarrierLine__c carrierLine = fuel.newCarrierLine();
- carrierLine.Carrier__c = carrier.Id;
- insert carrierLine;
- CarrierLineProduct__c product = fuel.newProduct();
- product.Carrier__c = carrier.Id;
- product.CarrierLine__c = carrierLine.Id;
- insert product;
- Application__c application = fuel.newApplication();
- application.RecordTypeId = '01236000000SKvhAAG';
- application.Policy_Number__c = 'W92745100';
- application.Tax_Status__c = 'Qualified';
- application.Gender__c = 'Male';
- application.Age__c = 43;
- application.Application_Stage__c = '00 - WV Preliminary App Review';
- application.Status__c = 'Reviewed by WV, App Not Submitted to Carrier';
- application.Investor__c = 'Sam Test';
- application.Carrier__c = carrier.Id;
- application.Product_Carrier__c = product.Id;
- application.Submitted_Premium__c = 100000;
- application.Sign_Date__c = System.today() - 7;
- application.Signed_State__c = 'CA';
- application.Application_Sent_To__c = 'WealthVest';
- application.Issue_Status_Only__c = 'Full Case Management';
- application.DOB__c = Date.newInstance(1975, 12, 9);
- application.Received_Date__c = System.today() - 2;
- application.Submitted__c = System.today();
- application.Submitted_Premium__c = 100000;
- application.Investor_SSN__c = '756342132';
- application.Carrier_Appointment__c = appointment.Id;
- insert application;
- Application_Line_Item__c ali = fuel.newApplicationLine();
- ali.Application__c = application.Id;
- insert ali;
- Producer_Application_Line_Item__c pali = fuel.newProducerApplicationLineItem();
- pali.Application_Line_Item__c = ali.Id;
- pali.Producer__c = contact.Id;
- pali.Split_pct__c = 100.00;
- insert pali;
- List<Application__c> applicationList = [SELECT Id FROM Application__c WHERE Id = :application.Id];
- System.assertEquals(1, applicationList.size());
- Test.startTest();
- List<Task> taskList = [SELECT Id, WhatId, CreatedDate FROM Task WHERE WhatId = :application.Id];
- System.assertEquals(true, taskList.isEmpty());
- try{
- application.Follow_Up_Date__c = System.today() + 2;
- update application;
- } catch(Exception e) {
- System.Assert(e.getMessage().contains('An activity must be logged today to change the Follow-Up Date'));
- }
- applicationList = [SELECT Id, Follow_Up_Date__c, Last_Activity_Date__c FROM Application__c WHERE Id = :application.Id];
- System.assertEquals(null, applicationList[0].Last_Activity_Date__c);
- System.assertNotEquals(System.today(), applicationList[0].Follow_Up_Date__c);
- Task task = new Task();
- task.recordTypeId = '01236000000OkDPAA0';
- task.ActivityDate = System.today();
- task.WhatId = application.Id;
- task.Type = 'OutBound Phone Call';
- task.Subject = 'Call';
- task.Status = 'Completed';
- task.CreatedDate = System.now() -1;
- task.LastModifiedDate = System.now() -1;
- Task task2 = new Task();
- task2.recordTypeId = '01236000000OkDPAA0';
- task2.ActivityDate = System.today() + 2;
- task2.WhatId = application.Id;
- task2.Type = 'Email';
- task2.Subject = 'Email';
- task2.Status = 'Completed';
- task2.CreatedDate = System.now();
- task2.LastModifiedDate = System.now();
- insert new List<Task>{task, task2};
- taskList = [SELECT Id, WhatId, CreatedDate FROM Task WHERE WhatId = :application.Id];
- System.assertEquals(2, taskList.size());
- application.Follow_Up_Date__c = System.today();
- update application;
- applicationList = [SELECT Id, Follow_Up_Date__c, Last_Activity_Date__c FROM Application__c WHERE Id = :application.Id];
- System.assertEquals(System.today(), applicationList[0].Last_Activity_Date__c);
- System.assertEquals(System.today(), applicationList[0].Follow_Up_Date__c);
- Test.stopTest();
- }
- }
- if (Trigger.isAfter && (Trigger.isUpdate || Trigger.isInsert)){
- if (ApplicationHandler.firstRun){
- handler.firstApplicationRun();
- handler.updateLastActivityDate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement