@isTest private class CampaignCostHandlerTest { @Testsetup static void init() { // Implement test code Campaign target1 = new Campaign(); target1.Name = 'test campaign1'; target1.Meeting_Type__c = '赞助会'; target1.IsDocLOGO__c = true; target1.IsDocLOGO__c = true; target1.formality1__c = true; target1.IsShowingEquipment__c = true; target1.IsAnimalExperience__c = true; target1.HostName__c = '会议主办方'; target1.cooperatorCompany__c = '会议承办方'; target1.isOther__c = true; string rec = Schema.SObjectType.Campaign.getRecordTypeInfosByDeveloperName().get('BusinessTraining').getRecordTypeId(); target1.RecordTypeId = rec; Campaign target2 = new Campaign(); target2.Name = 'test campaign2'; target2.RecordTypeId = rec; target2.Meeting_Type__c = '共同主办会'; target2.IsSatelliteMeeting__c = true; target2.HostName__c = '会议主办方'; target2.cooperatorCompany__c = '会议承办方'; target2.formality1__c = true; target2.isStand__c = true; target2.isTitle__c = true; insert new Campaign[] {target1, target2}; } @isTest static void testTrigger() { list CampaignList = [select id, Name from Campaign ]; Campaign target1 = CampaignList[0]; Campaign_Cost__c camCost1 = new Campaign_Cost__c(); camCost1.name = 'test1'; camCost1.Campaign__c = target1.id; upsert camCost1; target1.Campaign_Cost__c = camCost1.id; upsert target1; camCost1.name = 'test2'; upsert camCost1; delete camCost1; undelete camCost1; } @isTest static void test_checkUpdateShare() { User a = [select id from User where id = : userinfo.getuserid()]; System.runAs(a) { list CampaignList = [select id, Name from Campaign ]; Campaign target1 = CampaignList[0]; Campaign_Cost__c camCost1 = new Campaign_Cost__c(name = 'test1', Campaign__c = target1.id); Campaign_Cost__c camCost2 = new Campaign_Cost__c(name = 'test2', Campaign__c = target1.id); Campaign_Cost__c camCost3 = new Campaign_Cost__c(name = 'test3', Campaign__c = target1.id); Campaign_Cost__c camCost4 = new Campaign_Cost__c(name = 'test4', Campaign__c = target1.id); insert new Campaign_Cost__c[] {camCost1, camCost2, camCost3, camCost4}; user tempUser = new User(); camCost1.Sponsor_Ones_Post__c = '1.华北'; id tempUserId = getUser().id; camCost2.JingliApprovalManager__c = tempUserId; camCost3.BuchangApprovalManager__c = tempUserId; camCost4.ZongjianApprovalManager__c = tempUserId; update new Campaign_Cost__c[] {camCost1, camCost2, camCost3, camCost4}; } } private static User getUser() { String timenow = Datetime.now().format('yyyyMMddHHmmss'); User hpOwner = new User(Test_staff__c = true, LastName = 'TestMao', FirstName = 'TestMaoF', Alias = 'hp', CommunityNickname = 'TestMao', Email = 'Test@sunbridge.com', Username = 'Test' + timenow + '@sunbridge.com', IsActive = true, EmailEncodingKey = 'ISO-2022-JP', TimeZoneSidKey = 'Asia/Tokyo', LocaleSidKey = 'ja_JP', LanguageLocaleKey = 'ja', ProfileId = System.Label.ProfileId_SystemAdmin, Dept__c = '医疗华北营业本部', Province__c = '北京'); insert hpOwner; return hpOwner; } }