@isTest private class SubAuthorizedBatchTest { public static Account account1 = new Account(); public static Account account2 = new Account(); public static Contact contact1 = new Contact(); public static Contact contact2 = new Contact(); @isTest static void test_one() { account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; contact2.AccountId = account1.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test2医院'; insert contact2; List userList = new List(); Profile p = [select Id from Profile where Name = '系统管理员']; UserRole ur = [ SELECT Id, Name FROM UserRole where Name = 'OCSM SFDC管理员']; UserRole urtop = [ SELECT Id, Name FROM UserRole where Name = '总经理']; UserRole urdown = [ SELECT Id, Name FROM UserRole where Name = '信息系统本部']; string userinfoId = UserInfo.getUserId(); User tempUser = [select id from user where id = : userinfoId]; User user1 = 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'); user1.ProfileId = p.Id; user1.UserRoleId = ur.id; User user2; User user3; system.runAs(tempUser) { userList.add(user1); user2 = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = '2olympus_hpowner@sunbridge.com', Username = '2olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja'); user2.ProfileId = p.Id; user2.UserRoleId = urtop.id; userList.add(user2); insert userList; user3 = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner2', Email = '3olympus_hpowner@sunbridge.com', Username = '3olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja'); user3.ProfileId = p.Id; user3.UserRoleId = urdown.id; user3.ZongjianApprovalManager__c = user1.id; user3.TongkuoZongjian__c = user1.id; user3.BuchangApprovalManager__c = user1.id; user3.BuchangApprovalManagerSales__c = user1.id; user3.JingliApprovalManager__c = user1.id; user3.SalesManager__c = user1.id; user3.ManagerId = user1.id; user3.JingliEquipmentManager__c = user1.id; user3.Buzhang_Equipment_Manager__c = user1.id; insert user3; } system.runAs(user1) { SubAuthorized__c tempSubAuthor = new SubAuthorized__c(); tempSubAuthor.Status__c = '已批准'; tempSubAuthor.AuthorizedStartDate__c = Date.today().adddays(1); tempSubAuthor.AuthorizedEndDate__c = Date.today().adddays(2); tempSubAuthor.Authorizee__c = user2.id; tempSubAuthor.Authorizer__c = user1.id; insert tempSubAuthor; } Database.executeBatch(new SubAuthorizedBatch(), 1); } @isTest static void test_two() { account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; contact2.AccountId = account1.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test2医院'; insert contact2; List userList = new List(); Profile p = [select Id from Profile where Name = '系统管理员']; UserRole ur = [ SELECT Id, Name FROM UserRole where Name = 'OCSM SFDC管理员']; UserRole urtop = [ SELECT Id, Name FROM UserRole where Name = '总经理']; UserRole urdown = [ SELECT Id, Name FROM UserRole where Name = '信息系统本部']; string userinfoId = UserInfo.getUserId(); User tempUser = [select id from user where id = : userinfoId]; User user1 = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = '4hpOwner', Email = '5olympus_hpowner@sunbridge.com', Username = '4olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja'); user1.ProfileId = p.Id; user1.UserRoleId = ur.id; User user2; User user3; system.runAs(tempUser) { userList.add(user1); user2 = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = '5hpOwner1', Email = '5olympus_hpowner@sunbridge.com', Username = '5olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja'); user2.ProfileId = p.Id; user2.UserRoleId = urtop.id; userList.add(user2); insert userList; } system.runAs(user1) { SubAuthorized__c tempSubAuthor = new SubAuthorized__c(); tempSubAuthor.Status__c = '已批准'; tempSubAuthor.IsAuthorize__c = true; tempSubAuthor.AuthorizedStartDate__c = Date.today().adddays(-10); tempSubAuthor.AuthorizedEndDate__c = Date.today().adddays(-1); tempSubAuthor.Authorizee__c = user2.id; tempSubAuthor.Authorizer__c = user1.id; insert tempSubAuthor; } system.runAs(tempUser) { user3 = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = '6hpOwner2', Email = '6olympus_hpowner@sunbridge.com', Username = '6olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja'); user3.ProfileId = p.Id; user3.UserRoleId = urdown.id; user3.ZongjianApprovalManager_copy__c = user1.id; user3.TongkuoZongjian_copy__c = user1.id; user3.BuchangApprovalManager_copy__c = user1.id; user3.BuchangApprovalManagerSales_copy__c = user1.id; user3.JingliApprovalManager_copy__c = user1.id; user3.SalesManager_copy__c = user1.id; user3.ManagerId_copy__c = user1.id; user3.JingliEquipmentManager_copy__c = user1.id; user3.Buzhang_Equipment_Manager_copy__c = user1.id; insert user3; } Database.executeBatch(new SubAuthorizedBatch(), 1); } }