//(插入失败的第一个例外0行;第一个错误:STANDARD_PRICE_NOT_DEFINED,说明此产品没有定义标准价格:[])无法通过顶点插入记录定制价目表
全球一流SyncQuoteToOppLineItem { WebService static void callQuote(String oppID,String strQuoteID,String opLIId){System.debug('* *'+ oppID +''+ opLIId +''+ strQuoteID);
if(strQuoteID!=null){
List<OpportunityLineItem> oliList = new List<OpportunityLineItem>();
List<Product_Detail__c> lstPDet = new List<Product_Detail__c>();
List<Pricebook2> lstPRiceBook = [SELECT Id,IsActive,IsStandard,Name FROM Pricebook2 WHERE isActive = true AND IsStandard = false Limit 1];
if(lstPRiceBook.size()>0){
lstPDet = [SELECT AttachProduct__c,Name,Target_Rate__c,TotalCost__c,FlightStartDate__c,Adjusted_Rate__c,FlightEndDate__c,Game__c,Channel__c,OpportunityProducts__c,Target_Impression__c
FROM Product_Detail__c WHERE AttachProduct__c =:strQuoteID];
for(Product_Detail__c obPD:lstPDet){
//Get the Product ID
System.debug('**** obPD.Name ' + obPD.Name);
List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2.Name=:obPD.Name AND PriceBook2.id=:lstPRiceBook[0].id LIMIT 1];
if(priceBookList.size()>0){
OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppID, PricebookEntryId=priceBookList[0].Id,Cost_Per_Impression__c=obPD.Adjusted_Rate__c,
Game__c = obPD.Game__c, Platform__c=obPD.Channel__c);
oliList.add(oli);
}else{
//Inser the Prodcut and then add
Product2 p = new product2(name=obPD.Name,isActive=true);
insert p;
Id productId = p.id;
PricebookEntry pbe = new PricebookEntry(Pricebook2Id = lstPRiceBook[0].id, Product2Id = p.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
insert pbe;
//插入失败。第0行的第一个例外;第一个错误:STANDARD_PRICE_NOT_DEFINED,说明此产品没有定义标准价格:[]
OpportunityLineItem oli = new OpportunityLineItem(OpportunityId=oppID, PricebookEntryId=pbe.Id,Cost_Per_Impression__c=obPD.Adjusted_Rate__c,
Game__c = obPD.Game__c, Platform__c=obPD.Channel__c);
oliList.add(oli);
}
}
}