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..
Controller:
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;
}
}
VF Page:
<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>