You need to sign in to do that
Don't have an account?
kishore64
System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []
Hi all,
Here i am writng the test class like,
@isTest(seeAllData=true)
public class testSyncQuotaLineItemsCls{
public static testMethod void testSyncQuotaLineItemsCls(){
Contact con = New Contact();
con.LastName='test';
insert con;
Opportunity opp = new Opportunity();
opp.Name='test';
opp.CloseDate=Date.Today();
opp.StageName='Prospecting';
opp.Contact_del__c=con.id;
insert opp;
Quote qta = new Quote();
qta.Name='test';
qta.opportunityid=opp.id;
qta.Address_Information__c='Bangalore';
insert qta;
Sales_Order_LineItem__c soli = New Sales_Order_LineItem__c();
soli.Name='test';
insert soli;
Product2 pr = New Product2();
pr.Name='test';
pr.IsActive=true;
insert pr;
PriceBook2 pb2 = New PriceBook2();
pb2.Name = 'test';
pb2.IsActive=true;
// pb2.IsStandard=true;
insert pb2;
Pricebook2 p =[Select p.Id, p.Name from Pricebook2 p where isActive = true AND isStandard=true Limit 1];
PricebookEntry pb = New PricebookEntry();
pb.Product2Id = pr.Id;
pb.PriceBook2Id = pb2.id;
pb.UseStandardPrice = true;
pb.UnitPrice=35;
pb.isActive=true;
insert pb;
PricebookEntry pb1 = [select id,name,usestandardprice from PricebookEntry where usestandardprice=true];
QuoteLineItem qli = New QuoteLineItem();
qli.Product2Id=pr.id;
qli.UnitPrice=12;
qli.Quantity=5;
qli.QuoteId=qta.id;
qli.UnitPrice=35;
// qli.ListPrice=410;
//qli.Subtotal=123;
//qli.TotalPrice=410;
qli.PricebookEntryId=pb.id;
insert qli;
string qtaid = qta.id;
SyncQuotaLineItemsCls sqli = New SyncQuotaLineItemsCls();
SyncQuotaLineItemsCls.syncQLItoSLI(qtaid);
}
}
Error is: System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []
Here where i did mistake i don't know . please help me out .
Advance Thank you.
Here i am writng the test class like,
@isTest(seeAllData=true)
public class testSyncQuotaLineItemsCls{
public static testMethod void testSyncQuotaLineItemsCls(){
Contact con = New Contact();
con.LastName='test';
insert con;
Opportunity opp = new Opportunity();
opp.Name='test';
opp.CloseDate=Date.Today();
opp.StageName='Prospecting';
opp.Contact_del__c=con.id;
insert opp;
Quote qta = new Quote();
qta.Name='test';
qta.opportunityid=opp.id;
qta.Address_Information__c='Bangalore';
insert qta;
Sales_Order_LineItem__c soli = New Sales_Order_LineItem__c();
soli.Name='test';
insert soli;
Product2 pr = New Product2();
pr.Name='test';
pr.IsActive=true;
insert pr;
PriceBook2 pb2 = New PriceBook2();
pb2.Name = 'test';
pb2.IsActive=true;
// pb2.IsStandard=true;
insert pb2;
Pricebook2 p =[Select p.Id, p.Name from Pricebook2 p where isActive = true AND isStandard=true Limit 1];
PricebookEntry pb = New PricebookEntry();
pb.Product2Id = pr.Id;
pb.PriceBook2Id = pb2.id;
pb.UseStandardPrice = true;
pb.UnitPrice=35;
pb.isActive=true;
insert pb;
PricebookEntry pb1 = [select id,name,usestandardprice from PricebookEntry where usestandardprice=true];
QuoteLineItem qli = New QuoteLineItem();
qli.Product2Id=pr.id;
qli.UnitPrice=12;
qli.Quantity=5;
qli.QuoteId=qta.id;
qli.UnitPrice=35;
// qli.ListPrice=410;
//qli.Subtotal=123;
//qli.TotalPrice=410;
qli.PricebookEntryId=pb.id;
insert qli;
string qtaid = qta.id;
SyncQuotaLineItemsCls sqli = New SyncQuotaLineItemsCls();
SyncQuotaLineItemsCls.syncQLItoSLI(qtaid);
}
}
Error is: System.DmlException: Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []
Here where i did mistake i don't know . please help me out .
Advance Thank you.
Apex test class doesn't suport creating pricebook.
In summer '14 there is new method which can be used to create pricebook for you:-
Test.getStandardPricebookId();
Look at following example:
Also, you don't need (SeeAllData=true) then.
In summer 14 a new feature is added, you can get the id of standard pricebook by Test.getStandardPricebookId() this method will give you the id of standard price book.
You don't need to create any price book and use existing standard price book.
IF it helps you than please mark it as a solution and like it. ENJOY APEX
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AeOcIAK
I am doing in your way but it shows an exception because of unit price(43rd line) i uncommented that one. Now again i am executing this test class it shows some other exception i,e.
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: []
Then what can i do, i want to chnage any other thing please let me know......