liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
@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<User> userList=new List<User>();
                List<UserRole> 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<User> 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());
        // }
    }
}