@isTest private class CreateNewMaintenanceTaskBatchTest { static testMethod void testMethod1() { ControllerUtil.EscapeNFM007Trigger = true; ControllerUtil.EscapeNFM001Trigger = true; ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true; Oly_TriggerHandler.bypass('NFM106Controller.NFM106Trigger'); // Implement test code List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GS']; if (rectDpt.size() == 0) { return; } Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; // 病院作成 Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); insert hp; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GS']; // 診療科を作る Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id); dpt1.Name = '*'; dpt1.Department_Name__c = 'TestDepart1'; dpt1.ParentId = dc.Id; dpt1.Department_Class__c = dc.Id; dpt1.Hospital__c = hp.Id; insert dpt1; //正常 Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Status__c ='契約'; contract.Maintenance_Contract_No__c = 'Kami_Contract_No'; contract.Contract_Conclusion_Date__c = Date.today().addDays(-1); contract.Hospital__c = hp.Id; contract.Department_Class__c = dc.Id; contract.Department__c = dpt1.Id; contract.Contract_Start_Date__c = Date.today().addMonths(-1); contract.Contract_End_Date__c = Date.today().addMonths(11); contract.SalesOfficeCode_selection__c = '北京RC'; contract.Service_Contract_Staff__c = UserInfo.getUserId(); contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); insert contract; //顺延 (合同盖章完毕日 > [合同开始日 + 1个月] ) Maintenance_Contract__c contract2 = new Maintenance_Contract__c(); contract2.Name = 'tect contract2'; contract2.Status__c ='契約'; contract2.Maintenance_Contract_No__c = 'Kami_Contract_No2'; contract2.Contract_Conclusion_Date__c = Date.today().addDays(-1); contract2.Hospital__c = hp.Id; contract2.Department_Class__c = dc.Id; contract2.Department__c = dpt1.Id; contract2.Contract_Start_Date__c = Date.today().addMonths(-4); contract2.Contract_End_Date__c = Date.today().addMonths(16); contract2.Contract_print_completed__c = Date.today().addMonths(-3); contract2.SalesOfficeCode_selection__c = '北京RC'; contract2.Service_Contract_Staff__c = UserInfo.getUserId(); contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); insert contract2; //创建SLA任务 task__c task = new task__c(); task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('SLAReport_Task').getRecordTypeId(); task.taskDifferent__c = '被动任务'; task.taskStatus__c = '03 完成'; task.Activity_Date__c = Date.today(); task.account__c = dpt1.Id; task.Maintenance_Contract__c = contract.Id; insert task; //System.Test.StartTest(); Database.executeBatch(new CreateNewMaintenanceTaskBatch(true),200); //System.Test.StopTest(); } static testMethod void testMethod2() { ControllerUtil.EscapeNFM007Trigger = true; ControllerUtil.EscapeNFM001Trigger = true; ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true; Oly_TriggerHandler.bypass('NFM106Controller.NFM106Trigger'); // Implement test code List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'HP']; if (rectHp.size() == 0) { return; } List rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Department_GS']; if (rectDpt.size() == 0) { return; } Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', Work_Location__c = '北京', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert hpOwner; // 病院作成 Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); insert hp; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hp.Id and RecordType_DeveloperName__c = 'Department_Class_GS']; // 診療科を作る Account dpt1 = new Account(RecordTypeId = rectDpt[0].Id); dpt1.Name = '*'; dpt1.Department_Name__c = 'TestDepart1'; dpt1.ParentId = dc.Id; dpt1.Department_Class__c = dc.Id; dpt1.Hospital__c = hp.Id; insert dpt1; //正常 Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Status__c ='契約'; contract.Maintenance_Contract_No__c = 'Kami_Contract_No'; contract.Contract_Conclusion_Date__c = Date.today().addDays(-1); contract.Hospital__c = hp.Id; contract.Department_Class__c = dc.Id; contract.Department__c = dpt1.Id; contract.Contract_Start_Date__c = Date.today().addMonths(-1); contract.Contract_End_Date__c = Date.today().addMonths(11); contract.SalesOfficeCode_selection__c = '北京RC'; contract.Service_Contract_Staff__c = UserInfo.getUserId(); contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); insert contract; //顺延 (合同盖章完毕日 > [合同开始日 + 1个月] ) Maintenance_Contract__c contract2 = new Maintenance_Contract__c(); contract2.Name = 'tect contract2'; contract2.Status__c ='契約'; contract2.Maintenance_Contract_No__c = 'Kami_Contract_No2'; contract2.Contract_Conclusion_Date__c = Date.today().addDays(-1); contract2.Hospital__c = hp.Id; contract2.Department_Class__c = dc.Id; contract2.Department__c = dpt1.Id; contract2.Contract_Start_Date__c = Date.today().addMonths(-4); contract2.Contract_End_Date__c = Date.today().addMonths(16); contract2.Contract_print_completed__c = Date.today().addMonths(-3); contract2.SalesOfficeCode_selection__c = '北京RC'; contract2.Service_Contract_Staff__c = UserInfo.getUserId(); contract2.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); insert contract2; //创建SLA任务 task__c task = new task__c(); task.RecordTypeId = Schema.SObjectType.task__c.getRecordTypeInfosByDeveloperName().get('SLAReport_Task').getRecordTypeId(); task.taskDifferent__c = '被动任务'; task.taskStatus__c = '03 完成'; task.Activity_Date__c = Date.today(); task.account__c = dpt1.Id; task.Maintenance_Contract__c = contract.Id; insert task; //System.Test.StartTest(); Database.executeBatch(new ServiceMaintenanceHistoryBatch(),200); //System.Test.StopTest(); } }