@isTest private class OCSMTOTMSManageShareHandlerTest { @isTest static void myUnitTest() { //医院 List rectHp = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and DeveloperName = 'Agency']; if (rectHp.size() == 0) { return; } Profile p = [select Id from Profile where id =:System.Label.ProfileId_SystemAdmin]; User hpOwner = new User(Test_staff__c = true, LastName = 'hp', Alias = 'hp', Work_Location__c = '北京', 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 = p.id); User thisUser = [select Id from User where Id = :UserInfo.getUserId() ]; System.runAs ( thisUser ){ insert hpOwner; // 省 Address_Level__c al = new Address_Level__c(); al.Name = '广东省'; al.Level1_Code__c = 'CN-99'; al.Level1_Sys_No__c = '999999'; insert al; // 市 Address_Level2__c al2 = new Address_Level2__c(); al2.Level1_Code__c = 'CN-99'; al2.Level1_Sys_No__c = '999999'; al2.Level1_Name__c = '广东省'; al2.Name = '深圳市'; al2.Level2_Code__c = 'CN-9999'; al2.Level2_Sys_No__c = '9999999'; al2.Address_Level__c = al.id; insert al2; Account hp = new Account(RecordTypeId = rectHp[0].Id, Name = 'hp', OwnerId = thisUser.Id); hp.Name = 'test hospital'; hp.FSE_GI_Main_Leader__c = thisUser.Id; hp.FSE_SP_Main_Leader__c = thisUser.Id; hp.State_Master__c = al.id; hp.City_Master__c = al2.id; insert hp; OCM_Management_Province__c mp1 = new OCM_Management_Province__c(); mp1.Name = '深圳'; mp1.Province__c = '广州省'; mp1.Window1__c = hpOwner.Id; mp1.ET_DataWindow__c = hpOwner.Id; mp1.ET_BusinessWindow__c = hpOwner.Id; mp1.ET_Assistant1__c = hpOwner.Id; mp1.ET_Assistant2__c = hpOwner.Id; mp1.ENG_DataWindow__c = hpOwner.Id; mp1.ENG_BusinessWindow__c = hpOwner.Id; mp1.ENG_Assistant1__c = hpOwner.Id; mp1.ENG_Assistant2__c = hpOwner.Id; insert mp1; Dealer_ConsumableManage__c tms =new Dealer_ConsumableManage__c(); tms.Dealer_Name__c =hp.id; tms.ET_ENG__c ='ET'; tms.TMS_Key__c='1'; insert tms; tms.ET_ENG__c ='ENG'; update tms; // 共享计划创建 Dealer_ConsumableManage__Share tmsshare = new Dealer_ConsumableManage__Share(); tmsshare.RowCause= 'OCSMToTMSUser__c';//手动 tmsshare.ParentId = tms.id; tmsshare.UserOrGroupId = hpOwner.Id; tmsshare.AccessLevel = 'Read';//编辑 insert tmsshare; } } }