高章伟
2023-03-03 d8dc84a3d56df839895f1c417a4d9cbee763d262
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
@isTest
private class LastbuyProductHandlerTest {
    @isTest 
    static void TestMethod1() {
 
        Product2 pro = new Product2();
        pro.Name = 'Testname0215';
        pro.LastbuyProductFLG__c = false;
        insert pro;
 
        Product2 pro1 = new Product2();
        pro1.Name = 'Testname0216';
        pro1.LastbuyProductFLG__c = false;
        insert pro1;
 
        Address_Level__c al = new Address_Level__c();
        al.Name = '北京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '北京';
        al2.Name = '海淀区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
 
        Account company = new Account();
        company.Name = 'aiueo病院';
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.State_Master__c = al.Id;
        company.City_Master__c = al2.Id;
        insert company;
        
        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        depart.Name = '*';
        depart.Department_Name__c = 'aiueo診療科';
        depart.ParentId = sct.Id;
        depart.Department_Class__c = sct.Id;
        depart.Hospital__c = company.Id;
        insert depart;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        Opportunity opp1 = new Opportunity(Name = 'aiueo商談', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = false, AccountId = depart.Id);
        insert opp1;
        
        LastbuyProduct__c lbp = new LastbuyProduct__c();
        lbp.Name = 'Test0215';
        lbp.ProductName__c = pro.Id;
        lbp.InquiryCode__c = opp1.Id;
        lbp.effectiveFLG__c = true;
        insert lbp;
 
        lbp.effectiveFLG__c = false;
        update lbp;
 
        lbp.effectiveFLG__c = true;
        update lbp;
 
        delete lbp;
    }
 
    @isTest 
    static void TestMethod2() {
 
        Product2 pro = new Product2();
        pro.Name = 'Testname0215';
        pro.LastbuyProductFLG__c = false;
        insert pro;
 
        Address_Level__c al = new Address_Level__c();
        al.Name = '北京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '北京';
        al2.Name = '海淀区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
 
        Account company = new Account();
        company.Name = 'aiueo病院';
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.State_Master__c = al.Id;
        company.City_Master__c = al2.Id;
        insert company;
        
        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        depart.Name = '*';
        depart.Department_Name__c = 'aiueo診療科';
        depart.ParentId = sct.Id;
        depart.Department_Class__c = sct.Id;
        depart.Hospital__c = company.Id;
        insert depart;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        Opportunity opp1 = new Opportunity(Name = 'aiueo商談', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = true, AccountId = depart.Id);
        insert opp1;
 
        Opportunity opp2 = new Opportunity(Name = 'aiueo商談', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = false, AccountId = depart.Id);
        insert opp2;
 
        LastbuyProduct__c lbp = new LastbuyProduct__c();
        lbp.Name = 'Test0215';
        lbp.ProductName__c = pro.Id;
        lbp.InquiryCode__c = opp1.Id;
        lbp.effectiveFLG__c = true;
        insert lbp;
 
        try{
            lbp.InquiryCode__c = opp2.Id;
            update lbp;
        } catch (Exception e) {
            
        }
    }
 
    @isTest 
    static void TestMethod3() {
 
        Product2 pro = new Product2();
        pro.Name = 'Testname0215';
        pro.LastbuyProductFLG__c = false;
        insert pro;
 
        Address_Level__c al = new Address_Level__c();
        al.Name = '北京';
        al.Level1_Code__c = 'CN-99';
        al.Level1_Sys_No__c = '999999';
        insert al;
        // 市
        Address_Level2__c al2 = new Address_Level2__c();
        al2.Level1_Code__c = 'CN-99';
        al2.Level1_Sys_No__c = '999999';
        al2.Level1_Name__c = '北京';
        al2.Name = '海淀区';
        al2.Level2_Code__c = 'CN-9999';
        al2.Level2_Sys_No__c = '9999999';
        al2.Address_Level__c = al.id;
        insert al2;
 
        Account company = new Account();
        company.Name = 'aiueo病院';
        company.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId();
        company.State_Master__c = al.Id;
        company.City_Master__c = al2.Id;
        insert company;
        
        Account sct = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company.Id and RecordTypeId = :Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_Class_BF').getRecordTypeId() Limit 1];
        
        Account depart = new Account();
        depart.RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_BF').getRecordTypeId();
        depart.Name = '*';
        depart.Department_Name__c = 'aiueo診療科';
        depart.ParentId = sct.Id;
        depart.Department_Class__c = sct.Id;
        depart.Hospital__c = company.Id;
        insert depart;
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        Opportunity opp1 = new Opportunity(Name = 'aiueo商談', StageName = 'contact', CloseDate=Date.today(), SAP_Send_OK__c = true, AccountId = depart.Id);
        insert opp1;
 
        LastbuyProduct__c lbp = new LastbuyProduct__c();
        lbp.Name = 'Test0215';
        lbp.ProductName__c = pro.Id;
        lbp.InquiryCode__c = opp1.Id;
        lbp.effectiveFLG__c = true;
        insert lbp;
 
        try{
            delete lbp;
        } catch (Exception e) {
            
        }
    }
}