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
kishore64kishore64 

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.
Best Answer chosen by kishore64
Deepak Kumar ShyoranDeepak Kumar Shyoran
This error comes when you not define any Standard price for your Pricebook. You can get the Standard price book in test class by using (seeAllData = true) and with the help of following code
String standardPricebookId =Test.getStandardPricebookId();
List<PricebookEntry> entries = new List<PricebookEntry>();
entries.add(new PricebookEntry(Pricebook2Id = standardPricebookId, Product2Id = plist[0].Id, IsActive = true, UnitPrice = 100));       
insert entries; 

All Answers

Deepak Kumar ShyoranDeepak Kumar Shyoran
This error comes when you not define any Standard price for your Pricebook. You can get the Standard price book in test class by using (seeAllData = true) and with the help of following code
String standardPricebookId =Test.getStandardPricebookId();
List<PricebookEntry> entries = new List<PricebookEntry>();
entries.add(new PricebookEntry(Pricebook2Id = standardPricebookId, Product2Id = plist[0].Id, IsActive = true, UnitPrice = 100));       
insert entries; 

This was selected as the best answer
Deepak Kumar ShyoranDeepak Kumar Shyoran
And you can also create standard Pricebook in Test class as it's a new  Feature of Summer 14.
kishore64kishore64
Hi Deepak kumar Shyoran,

        I am doing in your way  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......
Deepak Kumar ShyoranDeepak Kumar Shyoran
This error comes when you trying to assign other type of Object Id to a Lookup or master Field of different type.
Let say as you have a Account lookup field on Contact and you want to insert a new contact by assigning an Opportunity id to the Account field on Contact and try to perform a DML then you'll get this Exception.
Opportunity opp = [Select id from Opportunity Limit 1] ;
Contact con = new Contact(LastName='TestName') ;
con.Account = opp.Id ;
insert con ; // You will this Field Integrate exception here due to above line


Please check in your code where you are getting this exception and assign a valid id for that field which is expected by that field.
kishore64kishore64
Thanks a  lot  Deepak for giving that explanation because i search in the google i am not find anything related to this error . Now i cleared that error everything is working fine......
Deepak Kumar ShyoranDeepak Kumar Shyoran
Welcome. Please close your question by selecting a best answer for your question so that it'll able for others as a solution to the same problem.