高章伟
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
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
@isTest
public with sharing class CreateOpportunityTaskBatchTest {
 
    @TestSetup
    static void makeData(){
        User user = new User(Test_staff__c = true);
        user.LastName = '_サンブリッジ';
        user.FirstName = 'う';
        user.Alias = 'う';
        user.Email = 'olympusTest03@sunbridge.com';
        user.Username = 'olympusTest03@sunbridge.com';
        user.CommunityNickname = 'う';
        user.IsActive = true;
        user.EmailEncodingKey = 'ISO-2022-JP';
        user.TimeZoneSidKey = 'Asia/Tokyo';
        user.LocaleSidKey = 'ja_JP';
        user.LanguageLocaleKey = 'ja';
        user.ProfileId = System.Label.ProfileId_SystemAdmin;
        user.Job_Category__c = '销售推广';
        user.Province__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();
 
        List<RecordType> rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
        if (rectCo.size() == 0) {
            return;
        }
        List<RecordType> rectSct = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '戦略科室分類 呼吸科'];
        if (rectSct.size() == 0) {
            return;
        }
        List<RecordType> rectDpt = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '診療科 消化科'];
        if (rectDpt.size() == 0) {
            return;
        }
 
 
        StaticParameter.EscapeOpportunityBefUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
        StaticParameter.EscapeNFM007Trigger = true;
        StaticParameter.EscapeOpportunityHpDeptUpdTrigger = true;
        StaticParameter.EscapeSyncOpportunityTrigger = true;
 
        System.runAs(new User(Id = Userinfo.getUserId())) {
            insert user;
            // テストデータ
            Account company = new Account();
            company.RecordTypeId = rectCo[0].Id;
            company.Name         = 'NFM007TestCompany';
            upsert company;
            Account section = new Account();
            section.RecordTypeId = rectSct[0].Id;
            section.Name         = '*';
            section.Department_Class_Label__c = '消化科';
            section.ParentId                  = company.Id;
            section.Hospital_Department_Class__c = company.Id;
            upsert section;
            Account depart = new Account();
            depart.RecordTypeId = rectDpt[0].Id;
            depart.Name         = '*';
            depart.Department_Name__c  = 'NFM007TestDepart';
            depart.ParentId            = section.Id;
            depart.Department_Class__c = section.Id;
            depart.Hospital__c         = company.Id;
            upsert depart;
 
            Opportunity opp = new Opportunity();
            opp.AccountId           = depart.Id;
            opp.Department_Class__c = section.Id;
            opp.Hospital__c         = company.Id;
            opp.SAP_Send_OK__c      = false;
            opp.Name                = 'GZ-SP-NFM007_1';
            opp.Trade__c            = '内貿';
            opp.StageName           = '引合';
            opp.CloseDate           = date.newinstance(2022, 11, 30);
            opp.Stock_apply_status__c = '申请中';
            opp.IsNextMonthOfVisit__c = false;
 
            opp.ET_SP_Consumption__c = false;
            opp.Opp_order_Type__c = '';
            opp.ThisPhase_Ship_Forecast__c  = false;
            opp.Equipment_Order_Flg__c  = false;
            opp.old_Oppo_No__c = '';
            opp.If_Account_Change__c  = false;
            // opp.ForecastAccuracyObject__c = true;
 
            // 待解决设置值后查询时为空的问题(batch中测试程序会跳过该条件)
            opp.OCM_man_province_cus_txt__c = '北京';
            opp.OCM_man_province_txt__c = '北京';
            // opp.SalesdepartmentForecast__c = '1.华北';
            insert opp;
        }        
    }
 
    @IsTest
    static void myTest(){
        
        Test.startTest();
            List<Opportunity> opps = [select id,name,StageName,ForecastAccuracyObject__c,SalesdepartmentForecast__c,
                                            OwnerId,Department_Name__c,AccountId,OCM_man_province_txt__c,OCM_man_province_cus_txt__c 
                                            from Opportunity];
            List<Id> testId = new List<Id>();
            testId.add(opps.get(0).Id);
            DataBase.executeBatch(new CreateOpportunityTaskBatch(testId));
        Test.stopTest();
        task__c myTask = [select id,Name from task__c];
        System.assertEquals('用户拜访:NFM007TestCompany 消化科 NFM007TestDepart', myTask.Name);   
    }
 
 
    @IsTest
    static void myTest2(){
        
        Test.startTest();
             DataBase.executeBatch(new CreateOpportunityTaskBatch());
        Test.stopTest();
        
    }
}