@isTest private class MaintenanceNewUpdateHandlerTest { static testMethod void testMethod1() { Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User MacOwner = new User(Test_staff__c = true, LastName = 'hp1', FirstName = 'owner1', Alias = 'hp', CommunityNickname = 'hpOwner1', Email = 'olympus_hpowner@sunbridge.com',Job_Category__c = '销售服务', Username = 'olympus_hpowner@sunbridge.com1', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = p.id); insert MacOwner; Account hospital = new Account(); hospital.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HP').getRecordTypeId(); hospital.Name = 'test hospita/l'; insert hospital; List strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.DeveloperName = 'Department_Class_GI']; Account dep = new Account(); dep.recordtypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Department_GI').getRecordTypeId(); dep.Name = 'test de/p'; dep.ParentId = strategicDep[0].Id; dep.Department_Class__c = strategicDep[0].Id; dep.Hospital__c = hospital.Id; insert dep; Maintenance_Contract__c contract = new Maintenance_Contract__c(); contract.Name = 'tect contract'; contract.Hospital__c = hospital.Id; contract.Department_Class__c = strategicDep[0].Id; contract.Department__c = dep.Id; contract.Service_Contract_Staff__c = MacOwner.Id; contract.Payment_Plan_Sum_First__c = 1; contract.Status__c = '契約'; contract.Maintenance_Contract_No__c = '11123'; contract.recordtypeId = Schema.SObjectType.Maintenance_Contract__c.getRecordTypeInfosByDeveloperName().get('NewMaintenance_Contract').getRecordTypeId(); contract.Not_Upper_limit_reason__c = ' 1'; contract.Contract_Start_Date__c = Date.today().addDays( -10); contract.Contract_End_Date__c = Date.today().addDays( 5); contract.SalesOfficeCode_selection__c = '北京RC'; insert contract; Maintenance_New_Update__c nObj = new Maintenance_New_Update__c(); nObj.Contract_Start_Date__c = Date.today(); nObj.Maintenance_Contract__c = contract.Id; insert nObj; nObj.Status__c = '审批中'; update nObj; nObj.Status__c = '已审批'; update nObj; } }