function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammad AnzarMohammad Anzar 

STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []


I am creating a wizard for Opportunity, Quote and QuoteLineItems. I am getting this error STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: [] while creating QuoteLineItems..

public class WizardClass 
{
    public Opportunity Oppo{get;set;}
    public List<Quote> quoteList{get;set;}
    public List<QuoteLineItem> quoteLineItemList{get;set;}
    public List<Quote> newQuoteList{get;set;}
    
    public WizardClass()
    {
        Oppo = new Opportunity();
        quoteList = new List<Quote>();
        quoteList.add(new quote());
        quoteLineItemList = new List<QuoteLineItem>();
        quoteLineItemList.add(new QuoteLineItem());
        }
    
    public void CreateQuote()
    {
        quoteList.add(new quote());
        }
        
    public void CreateQuoteLineItem()
    {
        quoteLineItemList.add(new QuoteLineItem());
        }
    
    public PageReference QuotePage()
    {
        return Page.OppoQuotes;
        }
         
       
    public PageReference Create()
    {
        
        insert Oppo; 
        List<Quote> quoList = new List<Quote>();
        for(Quote q : quoteList)
        {
            Quote quo = new Quote();
            quo.OpportunityId = Oppo.id;
            quo.name = q.name;
            quoList.add(quo);
            }
       // q.OpportunityId = Oppo.id;
        insert quoList;
        newQuoteList = quoList;
        PageReference newPage = new PageReference('/apex/OppoQuoteLine');
        return newPage;
        }
                
     public PageReference QuoteLineItemPage()
     {
       // Map<String,Quote> mapping = new Map<String,Quote>([Select id, name, (Select id, name From QuoteLineItem) From Quote]);
        List<QuoteLineItem> qliList = new List<QuoteLineItem>();
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'SLA: Bronze', IsActive = true);
        insert prod;
        PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 1000, IsActive = true);
        insert pbe;
        for(Quote q : newQuoteList)
        {
           for(quoteLineItem qli : quoteLineItemList)
           {
            QuoteLineItem qliObj = new QuoteLineItem();
            qliObj.QuoteId= q.id;
            qliObj.PriceBookEntryId = pbe.id;
            qliList.add(qli);
               }
            }      
        
        insert qliList;
        PageReference pg = new PageReference('/'+oppo.id);
        return pg;
        }           
                
}

<apex:page controller="WizardClass">
  <apex:form >
     <apex:sectionHeader title="OppoQuoteLine"/> 
        <apex:pageBlock >
           <apex:repeat value="{!quoteList}" var="row">
               <apex:outputField value="   {!row.name}" style="font-family :Arial, font-size : 12px" />
               <!--apex:repeat value="{!qliList}" var="r"-->
               <apex:pageBlockSection columns="1">
                  <apex:pageBlockTable var="row" value="{!quoteLineItemList}" id="pgt">
                      <!--apex:column headerValue="Price Book Entry">
                          <apex:inputField value="{!row.PriceBookEntryId}"/>
                      </apex:column-->
                      <!--apex:column headerValue="Quote Name">
                          <apex:inputField value="{!row.QuoteId}"/>
                      </apex:column-->
                      <apex:column headerValue="Sales Price">
                          <apex:inputField value="{!row.UnitPrice}"/>
                      </apex:column>
                      <apex:column headerValue="Quantity">
                          <apex:inputField value="{!row.Quantity}"/>
                      </apex:column>
                      <!--apex:column headerValue="Product">
                          <apex:inputField value="{!row.Product2Id}"/>
                      </apex:column-->
                  </apex:pageBlockTable>
              <apex:commandButton action="{!CreateQuoteLineItem}" value="Add Row" immediate="true" reRender="pgt"/>
              
               </apex:pageBlockSection>
               <!--/apex:repeat-->
           </apex:repeat>
           <apex:pageBlockButtons >           
                  <apex:commandButton action="{!QuoteLineItemPage}" value="Save"/>
           </apex:pageBlockButtons>
        </apex:pageBlock>
  </apex:form>
</apex:page>
Pankaj_GanwaniPankaj_Ganwani
Hi,

You will have to create PricebookEntry record with standard pricebook first and then create another PricebookEntry record with your custom pricebook for the same product.

You can refer the below mentioned link for more information:
https://developer.salesforce.com/forums/?id=906F00000008yveIAA
Mohammad AnzarMohammad Anzar

thanks for the reply Pankaj...A new error is coming now 

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, The pricebook entry is in a different pricebook than the one assigned to the Quote, or Quote has no pricebook assigned.: [PricebookEntryId]
Error is in expression '{!QuoteLineItemPage}' in component <apex:commandButton> in page oppoquoteline: Class.WizardClass.QuoteLineItemPage: line 89, column 1
 

Pankaj_GanwaniPankaj_Ganwani
Please associate the respective Quote with the same Pricebook that is being associated with QLIs. Quote must be assigned to same Pricebook for getting the QLIs records created in the org.

Use below mentioned statement to associate Quote with Pricebook:

quo.Pricebook2Id = pb.Id;