@isTest private class setOrderShareBatchTest { static testMethod void testMethod1() { Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'IE', ProductSegment__c = 'IE', TradeType__c = 'Taxation', SalesChannel__c = 'direct', MachineParts__c = 'Machine', isActive = true ); insert pricebook; Product2 product1 = new Product2(); product1.Name = 'product1'; Product2 product2 = new Product2(); product2.Name = 'product2'; Product2 product3 = new Product2(); product3.Name = 'product3'; insert new Product2[] {product1,product2,product3}; PricebookEntry standardPrice1 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product1.Id, UnitPrice = 0, IsActive = true, CurrencyIsoCode = 'CNY' ); PricebookEntry standardPrice2 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product2.Id, UnitPrice = 0, IsActive = true, CurrencyIsoCode = 'CNY' ); PricebookEntry standardPrice3 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product3.Id, UnitPrice = 0, IsActive = true, CurrencyIsoCode = 'CNY' ); insert new PricebookEntry[] {standardPrice1,standardPrice2,standardPrice3}; PricebookEntry entry1 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product1.Id); entry1.UnitPrice = 0; entry1.IsActive = true; entry1.UseStandardPrice = false; entry1.CurrencyIsoCode = 'CNY'; PricebookEntry entry2 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product2.Id); entry2.UnitPrice = 0; entry2.IsActive = true; entry2.UseStandardPrice = false; entry2.CurrencyIsoCode = 'CNY'; PricebookEntry entry3 = new PricebookEntry( Pricebook2Id=pricebook.Id, Product2Id=product3.Id); entry3.UnitPrice = 0; entry3.IsActive = true; entry3.UseStandardPrice = false; entry3.CurrencyIsoCode = 'CNY'; insert new PricebookEntry[] {entry1,entry2,entry3}; List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS']; Account accIE = new Account( Name = '*', RecordTypeId = rectIE[0].Id, OwnerId = UserInfo.getUserId(), DivisionName__c='Customer IE', FacilityName__c='abc', PostCode__c = '123456', DummyDealer__c = true ); insert accIE; List rectDealer = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Dealer']; // List rectIE = [select Id from RecordType where IsActive = true and SobjectType = 'Account' and Name = 'Customer BS']; Account buyer = new Account( Name = '*', FacilityName__c = 'buyer', PostCode__c = '123456', RecordTypeId = rectDealer[0].Id, ProductSegment__c = 'BS', DummyDealer__c = true ); Contact con = new Contact(); con.LastName = 'test'; con.AccountId = accIE.Id; con.MobilePhone = 'MobilePhoneD__c'; con.OtherPhone = 'OtherPhoneD__c'; con.Fax = 'FaxD__c'; con.Email = 'EmailD__c@test.com'; con.Phone = 'PhoneD__c'; con.Title = 'TitleD__c'; con.Address1__c = 'Address1D__c'; con.Address2__c = 'Address2D__c'; con.Address3__c = 'Address3D__c'; con.Postcode__c = '100111'; con.ContactStatus__c = 'ContactStatusD__c'; con.CancelReason__c = 'CancelReasonD__c'; con.StatusD__c = 'Pass'; insert con; Date day1 = Date.today(); List rectOpp = [select id from RecordType where IsActive = true and SobjectType = 'Opportunity']; // 有预定下单日 Opportunity opp = new Opportunity(); opp.Name = 'test opp'; opp.AccountId = accIE.Id; opp.Dealer__c = buyer.Id; opp.RecordTypeId = rectOpp[0].Id; opp.OwnerId = UserInfo.getUserId(); opp.StageName = 'Phase3'; opp.CurrencyIsoCode = 'CNY'; opp.ProductSegment__c = 'IE'; opp.CloseDate = Date.today(); opp.NewInquiryDate__c = Date.today().addDays(-2); opp.ExpectedOrderDate__c = Date.today().addDays(2); opp.ApprovalStatus_D__c = 'Pass'; opp.LeadSource = 'LeadSource_D__c'; opp.BudgetAmount__c = 111; opp.CancelReasonText__c = 'Cancel_Reason_Text_D__c'; opp.CancelReason__c = 'Cancel_reason_D__c'; opp.CompetitorCompany__c = 'Competitor_Company_D__c'; opp.Competitor_Product__c = 'Competitor_Product_D__c'; opp.Competitor_Product2__c = 'Competitor_Product2_D__c'; opp.Competitor_Product3__c = 'Competitor_Product3_D__c'; opp.Competitor_Product4__c = 'Competitor_Product4_D__c'; opp.Competitor_Product5__c = 'Competitor_Product5_D__c'; opp.Competitor_Product6__c = 'Competitor_Product6_D__c'; opp.Competitor_Product7__c = 'Competitor_Product7_D__c'; opp.Competitor_Product8__c = 'Competitor_Product8_D__c'; opp.CompetitorProductCode__c = 'Competitor_Product_Code_D__c'; opp.CompetitorProductCode2__c = 'Competitor_Product_Code2_D__c'; opp.CompetitorProductCode3__c = 'Competitor_Product_Code3_D__c'; opp.CompetitorProductCode4__c = 'Competitor_Product_Code4_D__c'; opp.CompetitorProductCode5__c = 'Competitor_Product_Code5_D__c'; opp.CompetitorProductCode6__c = 'Competitor_Product_Code6_D__c'; opp.CompetitorProductCode7__c = 'Competitor_Product_Code7_D__c'; opp.CompetitorProductCode8__c = 'Competitor_Product_Code8_D__c'; opp.DealerSalesStaffName__c = 'Dealer_Sales_Staff_Name_D__c'; opp.DealerService__c = 'Dealer_Service_D__c'; opp.ExpectedDeliveryDate__c = day1; opp.InquiryResult__c = 'InquiryResultD__c'; //opp.InquiryResultCancel__c = day1; //opp.InquiryResultLost__c = day1; opp.InquiryResultOrder__c = day1; opp.LostAmount__c = 111; opp.LostCompetitorProduct__c = 'Lost_competitor_product_D__c'; opp.LostReasonText__c = 'LostReasonText_D__c'; opp.LostReason__c = 'Lostreason_D__c'; opp.Phase1Date__c = day1; opp.Phase2Date__c = day1; opp.Phase3Date__c = day1; opp.SalesChannel__c = 'Sales_Channel_D__c'; //opp.SalesChannel__c = 'direct'; //opp.Machine_Parts__c = 'Parts'; opp.SubDealer__c = 'Sub_Dealer_D__c'; opp.TradeType__c = 'Trade_Type_D__c'; //opp.Pricebook2Id = pricebook.Id; insert opp; OpportunityContactRole role = new OpportunityContactRole( Role = 'End user', IsPrimary = true, OpportunityId = opp.Id, ContactId = con.Id ); insert role; Quote quo = new Quote( Name = 'quo', OpportunityId = opp.Id, //Pricebook2Id = pricebook.Id, SetName1__c = 'setname1', SetQty1__c = 1, SetName2__c = 'setname2', SetQty2__c = 2, Custom_Price_Total_Text__c = 1000 //IsSyncing = true ); insert quo; opp.SyncedQuoteId = quo.Id; update opp; List insertproductSets = new List(); productSet__c proSet1 = new productSet__c(); proSet1.Code__c = 'IXP-7P2'; proSet1.Name = 'IXP-7P2'; proSet1.IsValid__c = true; proSet1.Name = 'IXP-7P2'; insertproductSets.add(proSet1); productSet__c proSet2 = new productSet__c(); proSet2.Code__c = 'IXP-7P1SC'; proSet2.Name = 'IXP-7P1SC'; proSet2.IsValid__c = true; proSet2.Name = 'IXP-7P1SC'; insertproductSets.add(proSet2); productSet__c proSet3 = new productSet__c(); proSet3.Code__c = 'IXSP-T7LED'; proSet3.Name = 'IXSP-T7LED'; proSet3.IsValid__c = true; proSet3.Name = 'IXSP-T7LED'; insertproductSets.add(proSet3); insert insertproductSets; User user = new User(); user.LastName = 'testAccount'; user.FirstName = 'test'; user.Alias = '2105'; user.Email = 'testAccount@test.com'; user.Username = 'testAccount@test222.com'; user.CommunityNickname = 'testAccount'; user.IsActive = true; user.EmailEncodingKey = 'ISO-2022-JP'; user.TimeZoneSidKey = 'Asia/Tokyo'; user.LocaleSidKey = 'ja_JP'; user.LanguageLocaleKey = 'ja'; user.ProfileId = System.Label.SystemAdmin; insert user; AccountTeamMember atm = new AccountTeamMember(); atm.accountId = accIE.Id; atm.userId = user.Id;//'005280000071H0s'; atm.teamMemberRole = 'Sales Manager'; atm.ACCOUNTACCESSLEVEL = 'Edit'; atm.CONTACTACCESSLEVEL = 'Edit'; atm.OPPORTUNITYACCESSLEVEL = 'None'; atm.CASEACCESSLEVEL = 'None'; upsert atm; List rectOrder = [select id from RecordType where IsActive = true and SobjectType = 'Order']; Order odr = new Order( Name = '', Status = 'Draft', AccountId = accIE.Id, ApproveStatus__c = 'Draft', OpportunityId = opp.Id, EffectiveDate = Date.today(), RecordTypeId = '01228000000NJt6', confirm__c = false, SP_21__c = true, EndUser__c = con.Id ); insert odr; Order odr1 = new Order( Name = '', Status = 'Draft', AccountId = accIE.Id, ApproveStatus__c = 'Draft', OpportunityId = opp.Id, EffectiveDate = Date.today(), RecordTypeId = '01228000000NJt6', confirm__c = false, SP_21__c = true, EndUser__c = con.Id ); insert odr1; List orderIdList = new List(); orderIdList.add(odr.Id); database.executebatch(new setOrderShareBatch(),10); database.executebatch(new setOrderShareBatch(true),10); database.executebatch(new setOrderShareBatch(orderIdList),10); } @isTest static void test_method_one() { String CRON_EXP = '0 0 0 3 9 ? 2022'; System.Test.startTest(); String jobId = system.schedule('setOrderShareBatchScheduleTest', CRON_EXP, new setOrderShareBatchSchedule()); System.Test.StopTest(); } }