@isTest private class UpdateNewMaintenanceTaskBatchTest { static testMethod void testMethod1() { ControllerUtil.EscapeNFM001Trigger = true; ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true; // 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_GI']; 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_GI']; // 診療科を作る 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; //生成服务合同报告书 NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c(); tempNMCT.Name = 'FWreport-01'; tempNMCT.Distribution_Start_Date__c = Date.today(); tempNMCT.Distribution_End_Date__c = Date.today().addMonths(2).addDays(-1).addDays(30); tempNMCT.NewMaintenance_Contract__c = contract.Id; tempNMCT.ActualDistributionTimes_Quarter__c = 0; tempNMCT.OverOrCurrent__c = false; insert tempNMCT; Database.executeBatch(new UpdateNewMaintenanceTaskBatch(true)); } static testMethod void testMethod2() { ControllerUtil.EscapeNFM001Trigger = true; ControllerUtil.EscapeMaintenanceContractAfterUpdateTrigger = true; StaticParameter.EscapeNFM001Trigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger = true; StaticParameter.EscapeNFM001AgencyContractTrigger2 = true; StaticParameter.EscapeMaintenanceContractAfterUpdateTrigger = true; // 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_GI']; 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_GI']; // 診療科を作る 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; //生成服务合同报告书 NewMaintenanceReport_Task__c tempNMCT = new NewMaintenanceReport_Task__c(); tempNMCT.Name = 'FWreport-01'; tempNMCT.Distribution_Start_Date__c = Date.today(); tempNMCT.Distribution_End_Date__c = Date.today().addMonths(2).addDays(-1).addDays(30); tempNMCT.NewMaintenance_Contract__c = contract.Id; tempNMCT.ActualDistributionTimes_Quarter__c = 0; tempNMCT.OverOrCurrent__c = false; insert tempNMCT; Database.executeBatch(new UpdateNewMaintenanceTaskBatch()); } }