@isTest private class AccountDailyUpdateBatchTest { @isTest static void test_method_one() { // Implement test code Profile prof = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List classDeptStr = new List(); classDeptStr.add('Department_Class_GI'); classDeptStr.add('Department_Class_ET'); classDeptStr.add('Department_Class_BF'); classDeptStr.add('Department_Class_GS'); classDeptStr.add('Department_Class_URO'); classDeptStr.add('Department_Class_GYN'); classDeptStr.add('Department_Class_ENT'); classDeptStr.add('Department_Class_OTH'); List rectDept = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:classDeptStr]; Map classDeptMap = new Map(); if (rectHp.size() == 0) { return; } for(String Str : classDeptStr){ for(RecordType rt : rectDept){ if(rt.developername == Str){ classDeptMap.put(Str, rt.Id); } } } 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 = prof.id); insert hpOwner; Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectHp[0].Id,OwnerId = hpOwner.Id ); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='Plumber', accountid=myAccount1.id); insert core; List insertUser = new List(); user UserGI = New User( Alias = 'GI_User', Email='GI_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGI', Firstname ='GI', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGI@testorg.com'); insertUser.add(UserGI); user UserET = New User( Alias = 'ET_User', Email='ET_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserET', Firstname ='ET', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserET@testorg.com'); insertUser.add(UserET); user UserBF = New User( Alias = 'BF_User', Email='BF_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserBF', Firstname ='BF', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserBF@testorg.com'); insertUser.add(UserBF); user UserGS = New User( Alias = 'SP_User', Email='SP_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGS', Firstname ='GS', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGS@testorg.com'); insertUser.add(UserGS); user UserURO = New User( Alias = 'URO_User', Email='URO_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserURO', Firstname ='URO', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserURO@testorg.com'); insertUser.add(UserURO); user UserGYN = New User( Alias = 'GYN_User', Email='GYN_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGYN', Firstname ='GYN', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGYN@testorg.com'); insertUser.add(UserGYN); user UserENT = New User( Alias = 'ENT_User', Email='ENT_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserENT', Firstname ='ENT', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserENT@testorg.com'); insertUser.add(UserENT); user UserFSE = New User( Alias = 'FSEUser', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE', Firstname ='FSE', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE@testorg.com'); insertUser.add(UserFSE); insert insertUser; integer i = 0; for(user insU : insertUser){ insU.Employee_No__c = 'TestU'+i; i++; } update insertUser; Map NameTOno = New Map(); for(user usr : insertUser){ NameTOno.put(usr.Id, usr.Employee_No__c); } System.Test.startTest(); Account Hospital = new Account( name = 'Test Hospital', RecordTypeId = rectHp[0].Id, FSE_Main__c = UserFSE.Id, ENT_owner_ID__c = UserENT.Id, GYN_owner__c = UserGYN.Id, URO_owner_ID__c = UserURO.Id, SP_Main__c = UserGS.Id, BF_owner__c = UserBF.Id, ET_owner__c = UserET.Id, GI_Main__c = UserGI.Id ); insert Hospital; Hospital.Is_Active__c = '申请中'; update Hospital; Hospital.Is_Active__c ='有効'; update Hospital; Id execBTId = Database.executeBatch(new AccountDailyUpdateBatch(), 5); System.Test.stopTest(); } @isTest static void test_method_three() { // Implement test code Profile prof = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List classDeptStr = new List(); classDeptStr.add('Department_Class_GI'); classDeptStr.add('Department_Class_ET'); classDeptStr.add('Department_Class_BF'); classDeptStr.add('Department_Class_GS'); classDeptStr.add('Department_Class_URO'); classDeptStr.add('Department_Class_GYN'); classDeptStr.add('Department_Class_ENT'); classDeptStr.add('Department_Class_OTH'); List rectDept = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:classDeptStr]; Map classDeptMap = new Map(); if (rectHp.size() == 0) { return; } for(String Str : classDeptStr){ for(RecordType rt : rectDept){ if(rt.developername == Str){ classDeptMap.put(Str, rt.Id); } } } Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectHp[0].Id ); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='Plumber', accountid=myAccount1.id); insert core; List insertUser = new List(); user UserGI = New User( Alias = 'GI_User', Email='GI_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGI', Firstname ='GI', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGI@testorg.com'); insertUser.add(UserGI); user UserET = New User( Alias = 'ET_User', Email='ET_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserET', Firstname ='ET', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserET@testorg.com'); insertUser.add(UserET); user UserBF = New User( Alias = 'BF_User', Email='BF_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserBF', Firstname ='BF', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserBF@testorg.com'); insertUser.add(UserBF); user UserGS = New User( Alias = 'SP_User', Email='SP_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGS', Firstname ='GS', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGS@testorg.com'); insertUser.add(UserGS); user UserURO = New User( Alias = 'URO_User', Email='URO_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserURO', Firstname ='URO', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUseUROr@testorg.com'); insertUser.add(UserURO); user UserGYN = New User( Alias = 'GYN_User', Email='GYN_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGYN', Firstname ='GYN', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGYN@testorg.com'); insertUser.add(UserGYN); user UserENT = New User( Alias = 'ENT_User', Email='ENT_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserENT', Firstname ='ENT', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserENT@testorg.com'); insertUser.add(UserENT); user UserFSE = New User( Alias = 'FSE_User', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE', Firstname ='FSE', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE@testorg.com'); insertUser.add(UserFSE); user UserFSE_1 = New User( Alias = 'FSEUser1', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE1', Firstname ='FSE1', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE1@testorg.com'); insertUser.add(UserFSE_1); user UserFSE_2 = New User( Alias = 'FSEUser2', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE2', Firstname ='FSE2', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE2@testorg.com'); insertUser.add(UserFSE_2); user UserFSE_3 = New User( Alias = 'FSEUser3', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE3', Firstname ='FSE3', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE3@testorg.com'); insertUser.add(UserFSE_3); user UserTeamMember1 = New User( Alias = 'TMem1', Email='TeamMember1@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserTeamMember1', Firstname ='FSE', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserTeamMember1@testorg.com'); insertUser.add(UserTeamMember1); insert insertUser; Account Hospital = new Account( name = 'Test Hospital', RecordTypeId = rectHp[0].Id, FSE_Main__c = UserFSE.Id, ENT_owner_ID__c = UserENT.Id, GYN_owner__c = UserGYN.Id, URO_owner_ID__c = UserURO.Id, SP_Main__c = UserGS.Id, BF_owner__c = UserBF.Id, ET_owner__c = UserET.Id, GI_Main__c = UserGI.Id, GI_Product_Leader__c = 'testUserGSGS', GS_Product_Leader__c = 'testUserGSGS', GYN_Product_Leader__c = 'testUserGSGS', ET_Product_Leader__c = 'testUserGSGS', URO_Produc_Leader__c = 'testUserGSGS', BF_Product_Leader__c = 'testUserGSGS', ENT_Product_Leader__c = 'testUserGSGS', FSE_GI_Vice_Leader__c = 'testUserGSGS', FSE_SP_Vice_Leader__c = 'testUserGSGS', Energy_LeaderStr__c = 'FSE_User,FSE_User3', FSE_Extend_viceLeaderStr__c = 'FSE_User1,FSE_User3', Extend_Leader_Str__c = 'FSE_User2,FSE_User' ); System.Test.startTest(); insert Hospital; Hospital.Is_Active__c = '申请中'; update Hospital; Hospital.Is_Active__c ='有効'; update Hospital; AccountTeamMember CreateTM = new AccountTeamMember(); CreateTM.AccountId = Hospital.Id; CreateTM.UserId = UserTeamMember1.Id; CreateTM.TeamMemberRole = '営業担当'; insert CreateTM; //获取战略科室 //----消化科 List deptClassList = [select id,ParentId, name,recordType.developername from Account where RecordType.DeveloperName in:classDeptStr and parentId=:Hospital.Id ]; Map deptClassMaper = new Map(); for(Account acc : deptClassList){ for(RecordType rt : rectDept){ if(acc.recordType.developername == rt.developername){ classDeptMap.put(rt.developername, acc.Id); } } } //在消化科增加8个科室 List deptType = new List(); deptType.add('Department_ENT'); deptType.add('Department_GI'); deptType.add('Department_URO'); deptType.add('Department_GS'); deptType.add('Department_GYN'); deptType.add('Department_BF'); deptType.add('Department_OTH'); List rectDeptone = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:deptType]; Map depttypeMap = new Map(); for(String str : deptType){ for(RecordType RT : rectDeptone){ if(str == RT.developername){ depttypeMap.put(str, RT.Id); } } } Account deptGI = new Account( name = '消化科', parentId = classDeptMap.get('Department_Class_GI'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GI'), Department_Name__c = 'Test Hospital 消化科 消化科', RecordTypeId = depttypeMap.get('Department_GI') ); Account deptENT = new Account( name = '耳鼻喉科', parentId = classDeptMap.get('Department_Class_ENT'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_ENT'), Department_Name__c = 'Test Hospital 消化科 耳鼻喉科', RecordTypeId = depttypeMap.get('Department_ENT') ); Account deptURO = new Account( name = '泌尿科', parentId = classDeptMap.get('Department_Class_URO'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_URO'), Department_Name__c = 'Test Hospital 消化科 泌尿科', RecordTypeId = depttypeMap.get('Department_URO') ); Account deptGS = new Account( name = '普外科', parentId = classDeptMap.get('Department_Class_GS'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GS'), Department_Name__c = 'Test Hospital 消化科 普外科', RecordTypeId = depttypeMap.get('Department_GS') ); Account deptGYN = new Account( name = '婦人科', parentId = classDeptMap.get('Department_Class_GYN'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GYN'), Department_Name__c = 'Test Hospital 消化科 婦人科', RecordTypeId = depttypeMap.get('Department_GYN') ); Account deptBF = new Account( name = '呼吸科', parentId = classDeptMap.get('Department_Class_BF'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_BF'), Department_Name__c = 'Test Hospital 消化科 呼吸科', RecordTypeId = depttypeMap.get('Department_BF') ); Account deptOTH = new Account( name = 'その他', parentId = classDeptMap.get('Department_Class_OTH'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_OTH'), Department_Name__c = 'Test Hospital 消化科 その他', RecordTypeId = depttypeMap.get('Department_OTH') ); insert new Account[]{deptGI,deptBF,deptGYN,deptGS,deptURO,deptENT,deptOTH}; System.Test.stopTest(); //Account deptClassGI = new Account( // name = '战略科室-消化科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GI') // ); //Account deptClassET = new Account( // name = '战略科室-ET', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_ET') // ); //Account deptClassBF = new Account( // name = '战略科室-呼吸科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_BF') // ); //Account deptClassGS = new Account( // name = '战略科室-普外科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GS') // ); //Account deptClassURO = new Account( // name = '战略科室-泌尿科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_URO') // ); //Account deptClassGYN = new Account( // name = '战略科室-婦人科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GYN') // ); //Account deptClassENT = new Account( // name = '战略科室-耳鼻喉科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_ENT') // ); //Account deptClassOTH = new Account( // name = '战略科室-その他', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_OTH') // ); //insert new Account[]{deptClassGI,deptClassET,deptClassBF,deptClassGS,deptClassURO,deptClassGYN,deptClassENT,deptClassOTH}; AccountDailyUpdateBatch.executeWebSide(Hospital.Id); } @isTest static void test_method_two() { // Implement test code Profile prof = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List classDeptStr = new List(); classDeptStr.add('Department_Class_GI'); classDeptStr.add('Department_Class_ET'); classDeptStr.add('Department_Class_BF'); classDeptStr.add('Department_Class_GS'); classDeptStr.add('Department_Class_URO'); classDeptStr.add('Department_Class_GYN'); classDeptStr.add('Department_Class_ENT'); classDeptStr.add('Department_Class_OTH'); List rectDept = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:classDeptStr]; Map classDeptMap = new Map(); if (rectHp.size() == 0) { return; } for(String Str : classDeptStr){ for(RecordType rt : rectDept){ if(rt.developername == Str){ classDeptMap.put(Str, rt.Id); } } } Account myAccount1 = new Account(name='testaccount001',RecordTypeId = rectHp[0].Id ); insert myAccount1; Contact core = new Contact(email='jplumber@salesforce.com', firstname='Joe', lastname='Plumber', accountid=myAccount1.id); insert core; List insertUser = new List(); user UserGI = New User( Alias = 'GI_User', Email='GI_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGI', Firstname ='GI', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGI@testorg.com'); insertUser.add(UserGI); user UserET = New User( Alias = 'ET_User', Email='ET_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserET', Firstname ='ET', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserET@testorg.com'); insertUser.add(UserET); user UserBF = New User( Alias = 'BF_User', Email='BF_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserBF', Firstname ='BF', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserBF@testorg.com'); insertUser.add(UserBF); user UserGS = New User( Alias = 'SP_User', Email='SP_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGS', Firstname ='GS', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGS@testorg.com'); insertUser.add(UserGS); user UserURO = New User( Alias = 'URO_User', Email='URO_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserURO', Firstname ='URO', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUseUROr@testorg.com'); insertUser.add(UserURO); user UserGYN = New User( Alias = 'GYN_User', Email='GYN_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserGYN', Firstname ='GYN', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserGYN@testorg.com'); insertUser.add(UserGYN); user UserENT = New User( Alias = 'ENT_User', Email='ENT_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserENT', Firstname ='ENT', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserENT@testorg.com'); insertUser.add(UserENT); user UserFSE = New User( Alias = 'FSE_User', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE', Firstname ='FSE', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE@testorg.com'); insertUser.add(UserFSE); user UserFSE_1 = New User( Alias = 'FSEUser1', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE1', Firstname ='FSE1', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE1@testorg.com'); insertUser.add(UserFSE_1); user UserFSE_2 = New User( Alias = 'FSEUser2', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE2', Firstname ='FSE2', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE2@testorg.com'); insertUser.add(UserFSE_2); user UserFSE_3 = New User( Alias = 'FSEUser3', Email='FSE_User@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserFSE3', Firstname ='FSE3', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserFSE3@testorg.com'); insertUser.add(UserFSE_3); user UserTeamMember1 = New User( Alias = 'TMem1', Email='TeamMember1@testorg.com', EmailEncodingKey='UTF-8', LastName='testUserTeamMember1', Firstname ='FSE', LanguageLocaleKey='zh_CN', LocaleSidKey='zh_CN', ProfileId = System.Label.ProfileId_SystemAdmin, TimeZoneSidKey='Asia/Shanghai', UserName='testUserTeamMember1@testorg.com'); insertUser.add(UserTeamMember1); insert insertUser; Account Hospital = new Account( name = 'Test Hospital', RecordTypeId = rectHp[0].Id, FSE_Main__c = UserFSE.Id, ENT_owner_ID__c = UserENT.Id, GYN_owner__c = UserGYN.Id, URO_owner_ID__c = UserURO.Id, SP_Main__c = UserGS.Id, BF_owner__c = UserBF.Id, ET_owner__c = UserET.Id, GI_Main__c = UserGI.Id, GI_Product_Leader__c = 'testUserGSGS', GS_Product_Leader__c = 'testUserGSGS', GYN_Product_Leader__c = 'testUserGSGS', ET_Product_Leader__c = 'testUserGSGS', URO_Produc_Leader__c = 'testUserGSGS', BF_Product_Leader__c = 'testUserGSGS', ENT_Product_Leader__c = 'testUserGSGS', FSE_GI_Vice_Leader__c = 'testUserGSGS', FSE_ENG_Vice_Leader__c = 'testUserGSGS', FSE_SP_Vice_Leader__c = 'testUserGSGS', Energy_LeaderStr__c = 'FSE_User,FSE_User3', FSE_Extend_viceLeaderStr__c = 'FSE_User1,FSE_User3', Extend_Leader_Str__c = 'FSE_User2,FSE_User' ); System.Test.startTest(); insert Hospital; Hospital.Is_Active__c = '申请中'; update Hospital; Hospital.Is_Active__c ='有効'; update Hospital; AccountTeamMember CreateTM = new AccountTeamMember(); CreateTM.AccountId = Hospital.Id; CreateTM.UserId = UserTeamMember1.Id; CreateTM.TeamMemberRole = '営業担当'; insert CreateTM; //获取战略科室 //----消化科 List deptClassList = [select id,ParentId, name,recordType.developername from Account where RecordType.DeveloperName in:classDeptStr and parentId=:Hospital.Id ]; Map deptClassMaper = new Map(); for(Account acc : deptClassList){ for(RecordType rt : rectDept){ if(acc.recordType.developername == rt.developername){ classDeptMap.put(rt.developername, acc.Id); } } } //在消化科增加8个科室 List deptType = new List(); deptType.add('Department_ENT'); deptType.add('Department_GI'); deptType.add('Department_URO'); deptType.add('Department_GS'); deptType.add('Department_GYN'); deptType.add('Department_BF'); deptType.add('Department_OTH'); List rectDeptone = [select Id,developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:deptType]; Map depttypeMap = new Map(); for(String str : deptType){ for(RecordType RT : rectDeptone){ if(str == RT.developername){ depttypeMap.put(str, RT.Id); } } } Account deptGI = new Account( name = '消化科', parentId = classDeptMap.get('Department_Class_GI'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GI'), Department_Name__c = 'Test Hospital 消化科 消化科', RecordTypeId = depttypeMap.get('Department_GI') ); Account deptENT = new Account( name = '耳鼻喉科', parentId = classDeptMap.get('Department_Class_ENT'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_ENT'), Department_Name__c = 'Test Hospital 消化科 耳鼻喉科', RecordTypeId = depttypeMap.get('Department_ENT') ); Account deptURO = new Account( name = '泌尿科', parentId = classDeptMap.get('Department_Class_URO'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_URO'), Department_Name__c = 'Test Hospital 消化科 泌尿科', RecordTypeId = depttypeMap.get('Department_URO') ); Account deptGS = new Account( name = '普外科', parentId = classDeptMap.get('Department_Class_GS'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GS'), Department_Name__c = 'Test Hospital 消化科 普外科', RecordTypeId = depttypeMap.get('Department_GS') ); Account deptGYN = new Account( name = '婦人科', parentId = classDeptMap.get('Department_Class_GYN'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_GYN'), Department_Name__c = 'Test Hospital 消化科 婦人科', RecordTypeId = depttypeMap.get('Department_GYN') ); Account deptBF = new Account( name = '呼吸科', parentId = classDeptMap.get('Department_Class_BF'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_BF'), Department_Name__c = 'Test Hospital 消化科 呼吸科', RecordTypeId = depttypeMap.get('Department_BF') ); Account deptOTH = new Account( name = 'その他', parentId = classDeptMap.get('Department_Class_OTH'), Hospital__c = Hospital.Id, Department_Class__c = classDeptMap.get('Department_Class_OTH'), Department_Name__c = 'Test Hospital 消化科 その他', RecordTypeId = depttypeMap.get('Department_OTH') ); insert new Account[]{deptGI,deptBF,deptGYN,deptGS,deptURO,deptENT,deptOTH}; System.Test.stopTest(); //Account deptClassGI = new Account( // name = '战略科室-消化科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GI') // ); //Account deptClassET = new Account( // name = '战略科室-ET', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_ET') // ); //Account deptClassBF = new Account( // name = '战略科室-呼吸科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_BF') // ); //Account deptClassGS = new Account( // name = '战略科室-普外科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GS') // ); //Account deptClassURO = new Account( // name = '战略科室-泌尿科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_URO') // ); //Account deptClassGYN = new Account( // name = '战略科室-婦人科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_GYN') // ); //Account deptClassENT = new Account( // name = '战略科室-耳鼻喉科', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_ENT') // ); //Account deptClassOTH = new Account( // name = '战略科室-その他', // parentId = Hospital.Id, // RecordTypeId = classDeptMap.get('Department_Class_OTH') // ); //insert new Account[]{deptClassGI,deptClassET,deptClassBF,deptClassGS,deptClassURO,deptClassGYN,deptClassENT,deptClassOTH}; Id execBTId = Database.executeBatch(new AccountDailyUpdateBatch(2,'','','','',''), 5); execBTId = Database.executeBatch(new AccountDailyUpdateBatch(true), 5); execBTId = Database.executeBatch(new AccountDailyUpdateBatch('江南'), 5); } }