@isTest public class ServiceMaintenanceTaskConTest { static testMethod void testMethod1() { // 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 hospital = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); insert hospital; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hospital.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 = hospital.Id; insert dpt1; Asset asset = new Asset(); asset.Name = 'テスト機器'; asset.AccountId = dpt1.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hospital.Id; asset.SerialNumber = 'testserial'; asset.InstallDate = Date.newInstance(2020, 1, 1); asset.Guarantee_period_year__c = 3; asset.Posting_Date__c = Date.newInstance(2020, 1, 1); insert asset; 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.newInstance(2020, 1, 1); contract.Hospital__c = hospital.Id; contract.Department_Class__c = dc.Id; contract.Department__c = dpt1.Id; contract.Contract_Start_Date__c = Date.newInstance(2020, 1, 1); contract.Contract_End_Date__c = Date.newInstance(2023, 1, 1); contract.SalesOfficeCode_selection__c = '北京RC'; contract.Service_Contract_Staff__c = UserInfo.getUserId(); contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('Maintenance_Contract').getRecordTypeId(); contract.previousTotalContractAmount__c = 1; contract.currentTotalRepairAmount__c = 11111; insert contract; Maintenance_Contract__c contract1 = new Maintenance_Contract__c(); contract1.Name = 'tect contract1'; contract1.status__c ='契約'; contract1.Maintenance_Contract_No__c = 'Kami_Contract_No1'; contract1.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1); contract1.Hospital__c = hospital.Id; contract1.Department_Class__c = dc.Id; contract1.Department__c = dpt1.Id; contract1.Contract_Start_Date__c = Date.newInstance(2020, 1, 1); contract1.Contract_End_Date__c = Date.newInstance(2023, 1, 1); contract1.SalesOfficeCode_selection__c = '北京RC'; contract1.Service_Contract_Staff__c = UserInfo.getUserId(); contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); contract1.previousTotalContractAmount__c = 1; contract1.currentTotalRepairAmount__c = 11111; insert contract1; Maintenance_Task__c mainTask = new Maintenance_Task__c(); mainTask.Interval_Start_Date__c = Date.newInstance(2020, 7, 1); mainTask.Interval_End_Date__c = Date.newInstance(2020, 12, 31); mainTask.Reference_Consumption_Rate__c = 100; mainTask.Maintenance_Consumption_rate__c = 80; mainTask.Maintenance_Contract__c = contract.Id; mainTask.Is_Generate_Task__c = false; insert mainTask; Maintenance_Task__c mainTask1 = new Maintenance_Task__c(); mainTask1.Interval_Start_Date__c = Date.newInstance(2020, 7, 1); mainTask1.Interval_End_Date__c = Date.newInstance(2020, 12, 31); mainTask1.Reference_Consumption_Rate__c = 100; mainTask1.Maintenance_Consumption_rate__c = 80; mainTask1.Maintenance_Contract__c = contract1.Id; mainTask1.Is_Generate_Task__c = false; insert mainTask1; ServiceMaintenanceTaskController con = new ServiceMaintenanceTaskController(); con.mcIdList = contract.Id +','+contract1.Id; con.exportIdList = contract.Id +','+contract1.Id; con.init(); con.assignTasks(); con.exportAll(); // con.exportSelected(); } static testMethod void testMethod2() { // 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 hospital = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = hpOwner.Id); insert hospital; Account dc = [select Id, Name, RecordType_DeveloperName__c, Account2__c from Account where ParentId = :hospital.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 = hospital.Id; insert dpt1; Asset asset = new Asset(); asset.Name = 'テスト機器'; asset.AccountId = dpt1.Id; asset.Department_Class__c = dc.Id; asset.Hospital__c = hospital.Id; asset.SerialNumber = 'testserial'; asset.InstallDate = Date.newInstance(2020, 1, 1); asset.Guarantee_period_year__c = 3; asset.Posting_Date__c = Date.newInstance(2020, 1, 1); insert asset; 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.newInstance(2020, 1, 1); contract.Hospital__c = hospital.Id; contract.Department_Class__c = dc.Id; contract.Department__c = dpt1.Id; contract.Contract_Start_Date__c = Date.newInstance(2020, 1, 1); contract.Contract_End_Date__c = Date.newInstance(2023, 1, 1); contract.SalesOfficeCode_selection__c = '北京RC'; contract.Service_Contract_Staff__c = UserInfo.getUserId(); contract.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('Maintenance_Contract').getRecordTypeId(); contract.previousTotalContractAmount__c = 1; contract.currentTotalRepairAmount__c = 11111; insert contract; Maintenance_Contract__c contract1 = new Maintenance_Contract__c(); contract1.Name = 'tect contract1'; contract1.status__c ='契約'; contract1.Maintenance_Contract_No__c = 'Kami_Contract_No1'; contract1.Contract_Conclusion_Date__c = Date.newInstance(2020, 1, 1); contract1.Hospital__c = hospital.Id; contract1.Department_Class__c = dc.Id; contract1.Department__c = dpt1.Id; contract1.Contract_Start_Date__c = Date.newInstance(2020, 1, 1); contract1.Contract_End_Date__c = Date.newInstance(2023, 1, 1); contract1.SalesOfficeCode_selection__c = '北京RC'; contract1.Service_Contract_Staff__c = UserInfo.getUserId(); contract1.RecordTypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); contract1.previousTotalContractAmount__c = 1; contract1.currentTotalRepairAmount__c = 11111; insert contract1; Maintenance_Task__c mainTask = new Maintenance_Task__c(); mainTask.Interval_Start_Date__c = Date.newInstance(2020, 7, 1); mainTask.Interval_End_Date__c = Date.newInstance(2020, 12, 31); mainTask.Reference_Consumption_Rate__c = 100; mainTask.Maintenance_Consumption_rate__c = 80; mainTask.Maintenance_Contract__c = contract.Id; mainTask.Is_Generate_Task__c = false; insert mainTask; Maintenance_Task__c mainTask1 = new Maintenance_Task__c(); mainTask1.Interval_Start_Date__c = Date.newInstance(2020, 7, 1); mainTask1.Interval_End_Date__c = Date.newInstance(2020, 12, 31); mainTask1.Reference_Consumption_Rate__c = 100; mainTask1.Maintenance_Consumption_rate__c = 80; mainTask1.Maintenance_Contract__c = contract1.Id; mainTask1.Is_Generate_Task__c = false; insert mainTask1; ServiceMaintenanceTaskController con = new ServiceMaintenanceTaskController(); con.mcIdList = contract.Id +','+contract1.Id; con.exportIdList = contract.Id +','+contract1.Id; con.init(); // con.assignTasks(); // con.exportAll(); con.exportSelected(); con.moveToLast(); con.moveToNext(); con.moveToPrevious(); } }