高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@isTest
private class ChangedDepartmentOwnerTest {
    static testMethod void test01() {
        Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin];
        // ユーザー作成
        User subOwner = new User(Test_staff__c = true, LastName = 'oppSub', Province__c = '新疆自治区', Job_Category__c = '销售推广',
                FirstName = 'owner', Alias = 'hp', CommunityNickname = 'subOwner', Email = 'olympus_subowner@sb.com', Username = 'olympus_siubowner@sb.com',
                IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id
        );
        User subOwner2 = new User(Test_staff__c = true, LastName = 'oppSub2', Province__c = '新疆自治区', Job_Category__c = '销售推广',
                FirstName = 'owner', Alias = 'hp', CommunityNickname = 'subOwner2', Email = 'olympus_subowner2@sb.com', Username = 'olympus_siubowner2@sb.com',
                IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id
        );
        insert new User[] {subOwner, subOwner2};
        // 取引先作成
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        List<RecordType> rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 呼吸科'];
        Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'SoakupTestHp', OwnerId = UserInfo.getUserId(),
                OCM_Category__c = 'LLL'
        );
        insert hp;
        List<Account> dcs = [Select Id, Name, Department_Class_Label__c from Account where Parent.Id = :hp.Id and Department_Class_Label__c = '呼吸科'];
        
        Account depart = new Account();
        depart.RecordTypeId = rectDpt[0].Id;
        depart.Name         = '*';
        depart.Department_Name__c  = '診療科';
        depart.ParentId            = dcs[0].Id;
        depart.Department_Class__c = dcs[0].Id;
        depart.Hospital__c         = hp.Id;
        depart.OwnerId             = subOwner.Id;
        insert depart;
        
        RecordType rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity' and DeveloperName = 'Opportunity'];
        
        Opportunity opp = new Opportunity(
            Name = 'test opp',
            OwnerId = subOwner.Id,
            SAP_Province__c = '青海省',
            Opportunity_Category__c = 'GIGI',
            Distributor_InCharge_opp__c = true,
            StageName = '引合',
            CurrencyIsoCode = 'CNY',
            CloseDate = Date.today(),
            AccountId = depart.Id,
            RecordTypeId = rectOpp.Id,
            Closing_Bid_Date__c = Date.today().addDays(-5),
            Hospital__c = hp.Id,
            Competitor__c = 'A',
            owner_not_automatically_update__c = false
        );
        insert opp;
        List<Opportunity> opList = [Select Id, OwnerId from Opportunity];
        //System.assertEquals(opList[0].OwnerId, subOwner.Id);
        
        Test.startTest();
        depart.OwnerId = subOwner2.Id;
        hp.FSE_Main__c = subOwner2.Id;
        hp.FSE_Extend_viceLeaderStr__c = subOwner2.Id;
        hp.GI_Main__c = subOwner2.Id;
        hp.GI_Product_Leader__c = subOwner2.Id;
        hp.SP_Main__c = subOwner2.Id;
        hp.GS_Product_Leader__c = subOwner2.Id;
        hp.BF_owner__c = subOwner2.Id;
        hp.BF_Product_Leader__c = subOwner2.Id;
        hp.GYN_owner__c = subOwner2.Id;
        hp.GYN_Product_Leader__c = subOwner2.Id;
        hp.ET_owner__c = subOwner2.Id;
        hp.ET_Product_Leader__c = subOwner2.Id;
        hp.ENT_owner_ID__c = subOwner2.Id;
        hp.ENT_Product_Leader__c = subOwner2.Id;
        hp.URO_owner_ID__c = subOwner2.Id;
        hp.URO_Produc_Leader__c = subOwner2.Id;
        hp.FSE_GI_Main_Leader__c = subOwner2.Id;
        hp.FSE_GI_Vice_Leader__c = subOwner2.Id;
        hp.FSE_SP_Main_Leader__c = subOwner2.Id;
        hp.FSE_SP_Vice_Leader__c = subOwner2.Id;
        hp.FSE_ENG_Main_Leader__c = subOwner2.Id;
        hp.FSE_ENG_Vice_Leader__c = subOwner2.Id;
        hp.Extend_Leader_Str__c = subOwner2.Id;
        hp.Energy_LeaderStr__c = subOwner2.Id;
        update new Account[] {depart, hp};
        Test.stopTest();
 
        opList = [Select Id, OwnerId from Opportunity];
        //System.assertEquals(opList[0].OwnerId, subOwner2.Id);
    }
}