2014-02-25 30 views
0

//(插入失敗的第一個例外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

我假設你已經發現瞭如何通過今天現在解決這個問題,但如果沒有,我有這個確切的同樣的錯誤,發現答案在這裏:https://developer.salesforce.com/forums?id=906F00000008yveIAA

在未來,你應該知道你的問題的措辭不是很好,你應該問「不能通過APEX插入PriceBookEntry,未定義標準價格」或「無法通過APEX指定PriceBookEntry的標準價格」

使用例外的措辭來指導您尋找答案。