高章伟
2022-02-24 2aa8da8af66aa8ae00f25831aed6bb0364176e7b
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
@isTest
private class UpdateMeetingToContactBatchTest {
 
    @isTest static void test_method_one() {
        Test.startTest();
        Profile prof = [select Id from Profile where id = :System.Label.ProfileId_SystemAdmin];
        List<RecordType> rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院'];
 
        List<String> classDeptStr = new List<String>();
        classDeptStr.add('Department_Class_GI');
        classDeptStr.add('Department_Class_ET');
        classDeptStr.add('Department_Class_BF');
        classDeptStr.add('Department_Class_GS');
        classDeptStr.add('Department_Class_URO');
        classDeptStr.add('Department_Class_GYN');
        classDeptStr.add('Department_Class_ENT');
        classDeptStr.add('Department_Class_OTH');
        List<RecordType> rectDept = [select Id, developername from RecordType where IsActive = true and SobjectType = 'Account' and developername  in:classDeptStr];
 
        Map<String, String> classDeptMap = new Map<String, String>();
        if (rectHp.size() == 0) {
            return;
        }
        for (String Str : classDeptStr) {
            for (RecordType rt : rectDept) {
                if (rt.developername == Str) {
                    classDeptMap.put(Str, rt.Id);
                }
            }
        }
        User hpOwner = new User(Test_staff__c = true, LastName = 'hp', FirstName = 'owner', Alias = 'hp', CommunityNickname = 'hpOwner', Email = 'olympus_hpowner@sunbridge.com', Username = 'olympus_hpowner@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = prof.id);
        insert hpOwner;
        Campaign cam = new Campaign();
        cam.Name = 'cam';
        cam.Name2__c = '1234';
        cam.StartDate = Date.today().addDays(15);
        cam.EndDate = Date.today().addDays(18);
        insert cam;
        Account myAccount1 = new Account(name = 'testaccount001', RecordTypeId = rectHp[0].Id, OwnerId = hpOwner.Id );
        insert myAccount1;
        Contact core = new Contact(
            email = 'jplumber@salesforce.com',
            firstname = 'Joe',
            lastname = 'Plumber',
            accountid = myAccount1.id ,
            Campaign__c = cam.id,
            JobStatusUpdateDate__c = Date.today()
        );
        insert core;
        MeetingManagement__c tempMM = new MeetingManagement__c(
            pollingTime__c = 1,
            VisitTime__c = 1,
            InspectTime__c = 1,
            InspectEquipmentTime__c = 2,
            TeachingTime__c = 2,
            MaintenanceReportTime__c = 2,
            Contact__c = core.id,
            Campaign__c = cam.id,
            CreatedDate__c = Date.today()
        );
        insert tempMM;
        Instruct_report__c tempIR = new Instruct_report__c(
            Campaign__c = cam.id,
            Status__c = '批准'
        );
        insert tempIR;
        Test.stopTest();
 
        Instructed_staff__c tempIStaff = new Instructed_staff__c(
            Instruct_report__c = tempIR.id ,
            ContactID__c = core.id);
        
        insert tempIStaff;
        Database.executebatch(new UpdateMeetingToContactBatch(), 50);
        list<string> idList = new String[]{core.id}; 
        Database.executebatch(new UpdateMeetingToContactBatch(idList), 50);
 
    }
 
 
 
}