@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 rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; List classDeptStr = new List(); 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 rectDept = [select Id, developername from RecordType where IsActive = true and SobjectType = 'Account' and developername in:classDeptStr]; Map classDeptMap = new Map(); 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 idList = new String[]{core.id}; Database.executebatch(new UpdateMeetingToContactBatch(idList), 50); } }