@isTest private class TargetCustomerHandlerTest { @isTest static void test_method_one() { 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', 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; // 取引先作成 List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectHp.size() == 0) { return; } Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'AccountCaseHistoryTestHp1', OwnerId = hpOwner.Id); insert hp; List dc1s = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp.Id and Department_Class_Label__c in ('消化科')]; User deptPOwner = new User(Test_staff__c = true, LastName = 'deptP', FirstName = 'owner', Alias = 'deptP', CommunityNickname = 'deptPOwner', Email = 'olympus_deptpowner@sunbridge.com', Username = 'olympus_deptpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert deptPOwner; List getUsers = [select Id from User where LastName = 'deptP']; System.runAs(deptPOwner){ Date dateToday = Date.today(); Integer year = dateToday.year(); Integer month = dateToday.month(); if (month < 4) { year -= 1; } String selectedTab = String.valueOf(year - 1867 - 1 + 'P'); Account_Number_of_target__c anot = new Account_Number_of_target__c(); anot.Account__c = dc1s[0].Id; anot.Account_HP__c = hp.Id; anot.OCM_Period__c = selectedTab; anot.Target_amount_290Miro__c = 1; anot.Target_amount_3D__c = 1; anot.Target_amount_CHS400XZ__c = 1; anot.Target_amount_CV170__c = 1; anot.Target_amount_CV190__c = 1; anot.Target_amount_CV290__c = 1; anot.Target_amount_EUME2__c = 1; anot.Target_amount_OERAW__c = 1; anot.Target_amount_OTVS190__c = 1; anot.Target_amount_OTVS400__c = 1; anot.Target_amount_UCES3__c = 1; anot.Target_amount_USG400__c = 1; anot.Target_amount_GW__c = 1; anot.Department_Budget_Sum_Price__c = 1; anot.OPD_290Miro__c = 1; anot.OPD_3D__c = 1; anot.OPD_CHS400XZ__c = 1; anot.OPD_CV170__c = 1; anot.OPD_CV190__c = 1; anot.OPD_CV290__c = 1; anot.OPD_EUME2__c = 1; anot.OPD_OERAW__c = 1; anot.OPD_OTVS190__c = 1; anot.OPD_OTVS400__c = 1; anot.OPD_UCES3__c = 1; anot.OPD_USG400__c = 1; anot.OPD_GW__c = 1; //anot.Submit_Customer_target__c = true; insert anot; List gets = [select Id ,Name,TargetCustomerModifier__c from Account_Number_of_target__c]; system.assertEquals(getUsers[0].Id,gets[0].TargetCustomerModifier__c); anot.Target_amount_290Miro__c = 0; anot.Target_amount_3D__c = 0; anot.Target_amount_CHS400XZ__c = 0; anot.Target_amount_CV170__c = 0; anot.Target_amount_CV190__c = 0; anot.Target_amount_CV290__c = 0; anot.Target_amount_EUME2__c = 0; anot.Target_amount_OERAW__c = 0; anot.Target_amount_OTVS190__c = 0; anot.Target_amount_OTVS400__c = 0; anot.Target_amount_UCES3__c = 0; anot.Target_amount_USG400__c = 0; anot.Target_amount_GW__c = 0; anot.Department_Budget_Sum_Price__c = 0; anot.OPD_290Miro__c = 0; anot.OPD_3D__c = 0; anot.OPD_CHS400XZ__c = 0; anot.OPD_CV170__c = 0; anot.OPD_CV190__c = 0; anot.OPD_CV290__c = 0; anot.OPD_EUME2__c = 0; anot.OPD_OERAW__c = 0; anot.OPD_OTVS190__c = 0; anot.OPD_OTVS400__c = 0; anot.OPD_UCES3__c = 0; anot.OPD_USG400__c = 0; anot.OPD_GW__c = 0; //anot.Submit_Customer_target__c = false; update anot; } } }