//(插入失败。第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);
}
}
}
答案 0 :(得分:0)
我假设您现在已经发现了如何解决这个问题,但如果没有,我今天也遇到了同样的错误,并在此处找到答案:https://developer.salesforce.com/forums?id=906F00000008yveIAA
将来你应该知道问题的措辞不是很好;你应该问过一些问题,“不能通过APEX插入PriceBookEntry,标准价格未定义”或“不能通过APEX指定PriceBookEntry的标准价格”
使用例外措辞来帮助指导您搜索答案。