@isTest private class PaymentMaintenanceContractTriggerHTest { static testMethod void testMethod1() { // 取引先 ID RecordTypeId1 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('医院').getRecordTypeId(); ID RecordTypeId2 = Schema.SObjectType.Account.getRecordTypeInfosByName().get('经销商').getRecordTypeId(); Account account1 = new Account(); account1.Name = 'test1医院'; account1.RecordTypeId = RecordTypeId1; insert account1; // Account account2 = new Account(); // account2.Name = 'test1经销商'; // account2.RecordTypeId = RecordTypeId2; // 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; MaintanceContractPack__c target01 = new MaintanceContractPack__c(); target01.Name = 'TestDBMC'; target01.SalesOfficeCode_selection__c = '北京RC'; target01.Contract_Type__c = '上限合同'; target01.Is_Standard_Contract__c = '是'; target01.Inspection_Time__c = '1'; target01.Total_Payment_Time__c = '1'; target01.Term_Of_Payment__c = '多次付款'; target01.Contract_Start_Date__c = Date.today(); target01.Contract_End_Date__c = Date.today().addMonths(+12); target01.URF_Contract__c = false; target01.Contract_Range__c = Decimal.valueOf('12'); insert target01; ID RecordTypeId3 = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByName().get('服务合同').getRecordTypeId(); //新建维修合同 Maintenance_Contract__c test = new Maintenance_Contract__c(); test.Name = 'Test合同'; test.RecordTypeId= RecordTypeId3; test.Department__c = depart1.Id; test.Management_Code__c = 'BJ-RS-BJ0062233'; test.Status__c = '询价中'; test.MaintanceContractPack__c = target01.id; test.Service_Contract_Staff__c = UserInfo.getUserId(); 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; pmc.Amount__c = 234.23; update pmc; // Payment_Maintenance_Contract__c pmc1 = new Payment_Maintenance_Contract__c(); // pmc1.Find_Dealers__c = account1.id; // pmc1.Find_Contact__c = test.id; // pmc1.Amount__c = 123.23; // //pmc1.Employees__c = ac1.Id; // pmc1.ReceiveNo__c = '134'; // pmc1.ReceiveNoKey__c = '3245'; // pmc1.DeleteFlag__c = 'X'; // insert pmc1; } }