@isTest private class PaymentMaintenanceContractTriggerTest { static testMethod void testMethod1() { // 取引先 Account account1 = new Account(); account1.Name = 'test1医院'; account1.RecordTypeId = '01210000000QemG'; insert account1; Account account2 = new Account(); account2.Name = 'test1经销商'; account2.RecordTypeId = '01210000000Qem1'; insert account2; Contact contact2 = new Contact(); contact2.AccountId = account1.Id; contact2.FirstName = '責任者'; contact2.LastName = 'test2医院'; insert contact2; // ユーザー Profile p = [select Id from Profile where Name = '901_经销商活动系统']; User user = new User(); user.ProfileId = p.Id; user.ContactId = contact2.Id; user.FirstName = 'ユーザー'; user.LastName = 'テスト'; user.Email = 'test_user@example.com'; user.emailencodingkey='UTF-8'; user.languagelocalekey='zh_CN'; user.localesidkey='ja_JP'; user.timezonesidkey='Asia/Shanghai'; user.Username = 'test_user@example.com'; user.Alias = 'テユ'; user.CommunityNickname = 'テストユーザー'; insert user; // 代理店医院 Agency_Hospital_Link__c agency_hospital_link = new Agency_Hospital_Link__c(); agency_hospital_link.Name = 'test1代理店医院'; agency_hospital_link.Hospital__c = account1.Id; agency_hospital_link.Agency__c = account2.Id; agency_hospital_link.OwnerId = user.Id; insert agency_hospital_link; Agency_Contact__c ac1 = new Agency_Contact__c(); ac1.Name = 'test1のび太'; ac1.Agency_Hospital__c = agency_hospital_link.Id; insert ac1; List rectCo = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = '病院']; if (rectCo.size() == 0) { return; } List rectDpt = [select Id, Name from RecordType where IsActive = true and SobjectType = 'Account' and Name IN ('診療科 消化科', '診療科 呼吸科') order by Name desc]; if (rectDpt.size() == 0) { return; } Account company1 = new Account(); company1.RecordTypeId = rectCo[0].Id; company1.Name = '病院テスト1'; List hps = new Account[]{company1}; insert hps; List dc1s = [Select Id, Name, Department_Class_Label__c, Sys_Dept_Name_Change_Chk__c from Account where Parent.Id = :company1.Id order by Department_Class_Label__c]; Account depart1 = new Account(); depart1.RecordTypeId = rectDpt[0].Id; depart1.Name = '*'; depart1.Department_Name__c = '診療科1'; depart1.ParentId = dc1s[0].Id; depart1.Department_Class__c = dc1s[0].Id; depart1.Hospital__c = company1.Id; insert depart1; //新建维修合同 Maintenance_Contract__c test = new Maintenance_Contract__c(); test.Name = 'Test合同'; test.RecordTypeId='01210000000QjeF'; test.Department__c = depart1.Id; test.Management_Code__c = 'BJ-RS-BJ0062233'; test.Status__c = '询价中'; test.Service_Contract_Staff__c = user.Id; insert test; Payment_Maintenance_Contract__c pmc = new Payment_Maintenance_Contract__c(); pmc.Find_Dealers__c = account1.id; pmc.Find_Contact__c = test.id; pmc.Amount__c = 123.23; //pmc.Employees__c = ac1.Id; pmc.ReceiveNo__c = '134'; pmc.ReceiveNoKey__c = '3245'; insert pmc; } }