@isTest private class InventoryTaskAndEmailBatchTest { static testMethod void testMethod1() { // try{ // MIXED_DML_OPERATION, DML operation on setup object is not permitted Error // System.runAs(new User(Id = Userinfo.getUserId())) { StaticParameter.EscapeContactToUser = true; Oly_TriggerHandler.bypass('UserProfileHandler'); Oly_TriggerHandler.bypass(UserProfileHandler.Class.getName()); List userList=new List(); List urL=[select id from UserRole where name = '备品中心北方管理成员']; User user = new User(Test_staff__c = true); user.LastName = '_サンブリッジ111'; user.FirstName = 'う111'; user.Alias = 'う1'; user.Email = 'olympusTest01@sunbridge.com'; user.Username = 'olympusTest01@sunbridge.com'; user.CommunityNickname = 'う1'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.ProfileId_2B2P; user.Job_Category__c = '销售推广'; user.Province__c = '上海市'; user.Dept__c='医疗华北营业本部'; user.Use_Start_Date__c = Date.today().addMonths(-6); user.SalesManager__c = UserInfo.getUserId(); user.BuchangApprovalManagerSales__c = UserInfo.getUserId(); user.JingliApprovalManager__c = UserInfo.getUserId(); user.BuchangApprovalManager__c = UserInfo.getUserId(); user.ZongjianApprovalManager__c = UserInfo.getUserId(); if(urL.size()>0){ user.UserRoleId=urL.get(0).Id; } userList.add(user); urL=[select id from UserRole where name = '备品中心华东管理成员']; User user1 = new User(Test_staff__c = true); user1.LastName = '_サンブリッジ222'; user1.FirstName = 'う222'; user1.Alias = 'う2'; user1.Email = 'olympusTest02@sunbridge.com'; user1.Username = 'olympusTest02@sunbridge.com'; user1.CommunityNickname = 'う2'; user1.IsActive = true; user1.EmailEncodingKey = 'ISO-2022-JP'; user1.TimeZoneSidKey = 'Asia/Tokyo'; user1.LocaleSidKey = 'ja_JP'; user1.LanguageLocaleKey = 'ja'; user1.ProfileId = System.Label.ProfileId_2B2P; user1.Job_Category__c = '销售推广'; user1.Province__c = '上海市'; user1.Dept__c='医疗华北营业本部'; user1.Use_Start_Date__c = Date.today().addMonths(-6); user1.SalesManager__c = UserInfo.getUserId(); user1.BuchangApprovalManagerSales__c = UserInfo.getUserId(); user1.JingliApprovalManager__c = UserInfo.getUserId(); user1.BuchangApprovalManager__c = UserInfo.getUserId(); user1.ZongjianApprovalManager__c = UserInfo.getUserId(); if(urL.size()>0){ user1.UserRoleId=urL.get(0).Id; } userList.add(user1); urL=[select id from UserRole where name = '备品中心南方管理成员']; User user2 = new User(Test_staff__c = true); user2.LastName = '_サンブリッジ333'; user2.FirstName = 'う333'; user2.Alias = 'う3'; user2.Email = 'olympusTest04@sunbridge.com'; user2.Username = 'olympusTest04@sunbridge.com'; user2.CommunityNickname = 'う3'; user2.IsActive = true; user2.EmailEncodingKey = 'ISO-2022-JP'; user2.TimeZoneSidKey = 'Asia/Tokyo'; user2.LocaleSidKey = 'ja_JP'; user2.LanguageLocaleKey = 'ja'; user2.ProfileId = System.Label.ProfileId_2B2P; user2.Job_Category__c = '销售推广'; user2.Province__c = '上海市'; user2.Dept__c='医疗华北营业本部'; user2.Use_Start_Date__c = Date.today().addMonths(-6); user2.SalesManager__c = UserInfo.getUserId(); user2.BuchangApprovalManagerSales__c = UserInfo.getUserId(); user2.JingliApprovalManager__c = UserInfo.getUserId(); user2.BuchangApprovalManager__c = UserInfo.getUserId(); user2.ZongjianApprovalManager__c = UserInfo.getUserId(); if(urL.size()>0){ user2.UserRoleId=urL.get(0).Id; } userList.add(user2); // if (Test.isRunningTest()) { // System.runAs(new User(Id = UserInfo.getUserId())){ // } // } System.runAs(new User(Id = Userinfo.getUserId())) { System.Test.startTest(); insert userList; Database.executeBatch(new InventoryTaskAndEmailBatch(), 100); System.Test.stopTest(); } // System.Test.startTest(); // List rl=[SELECT Id, Email, RoleName_wave__c FROM User WHERE Profile.Name = '2B2_备品中心检测&仓库管理(照片)' AND IsActive = true]; // System.debug('rrrrrrrrrrrrrrrrrrrr:'+rl); // Database.executeBatch(new InventoryTaskAndEmailBatch(), 1); // System.debug('end'); // System.Test.stopTest(); // } // }catch(Exception e){ // System.debug('test error:'+e.getMessage()); // } } }