@isTest private class SBG010WebServiceTest { static String setdata(){ Id pricebookId = Test.getStandardPricebookId(); Pricebook2 pricebook = new Pricebook2( Name = 'BS', 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 ); PricebookEntry standardPrice2 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product2.Id, UnitPrice = 0, IsActive = true ); PricebookEntry standardPrice3 = new PricebookEntry( Pricebook2Id = pricebookId, Product2Id = product3.Id, UnitPrice = 0, IsActive = true ); 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 IE']; Account accIE = new Account( Name = '*', RecordTypeId = rectIE[0].Id, OwnerId = UserInfo.getUserId(), DivisionName__c='Customer IE', FacilityName__c='abc', PostCode__c = '123456' ); insert accIE; 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.RecordTypeId = rectOpp[0].Id; opp.OwnerId = UserInfo.getUserId(); opp.StageName = 'Prospect Created'; 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.SubDealer__c = 'Sub_Dealer_D__c'; opp.TradeType__c = 'Trade_Type_D__c'; //opp.Machine_Parts__c = 'Machine_Parts_D__c'; //opp.SpecialDeliveryAddress__c = 'SpecialDeliveryAddress_D__c'; //opp.ForeignTradeCompany__c = 'ForeignTradeCompany_D__c'; insert opp; OpportunityLineItem oli = new OpportunityLineItem(); oli.OpportunityId = opp.Id; oli.Quantity = 2; oli.UnitPrice = 111; oli.Description = 'test'; oli.PricebookEntryId = entry1.Id; insert oli; 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' ); insert odr; Delivery__c de1 = new Delivery__c(); de1.SSBD_Contract__c = odr.Id; insert de1; Order ordd = [Select OrderNumber,Id,Name From Order]; return ordd.OrderNumber; } @isTest static void test_method_one() { String ocode = setdata(); SBG010WebService.GeData GeData = new SBG010WebService.GeData(); GeData.OrderCode = ocode; SBG010WebService.GeDatas datas = new SBG010WebService.GeDatas(); datas.GeData = new List(); datas.GeData.add(GeData); datas.Monitoring = new NFMUtil.Monitoring(); SBG010WebService.SBG010(datas); } @isTest static void test_method_two() { String ocode = setdata(); System.debug(ocode); SBG010WebService.GeData GeData = new SBG010WebService.GeData(); GeData.OrderCode = ocode; GeData.SoNo = '123'; GeData.SoShippingStatus = '123'; SBG010WebService.GeDatas datas = new SBG010WebService.GeDatas(); datas.GeData = new List(); datas.GeData.add(GeData); datas.Monitoring = new NFMUtil.Monitoring(); SBG010WebService.SBG010(datas); } }