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
majomajo 

Insert failed. No standard price difined for this product - help!

hi,

I'm trying to create a test class for a trigger:

 

trigger deleteTask on OpportunityLineItem (before delete) {

List<OpportunityLineItem> OppLIs = Trigger.old;
List<Task> tasks = new List<Task>();

for (OpportunityLineItem OppLI : OppLIs) {

Opportunity Opp = [ Select OwnerId from Opportunity where id=:OppLI.OpportunityId limit 1 ];
User usuario = [ Select Sociedad__c from User where id=:Opp.OwnerId ];

//el usuario debe pertenecer a argentina = usuario.Sociedad__c == 1000
if ( usuario.Sociedad__c == '1000' ) {
tasks = [ Select Id from Task where whatID=:OppLI.OpportunityId and Subject='Recordatorio: Vencimiento de producto'];
}
}

delete tasks;

}

 

My test class is:

 

@isTest
private class deleteTaskTest {

static testMethod void myUnitTest() {

//Create a custom pricebook
Pricebook2 pb = new Pricebook2(Name='Custom Pricebok',IsActive=true);
insert pb;

// Create a new product
Product2 prod = new Product2(IsActive=true, Name='Product');
insert prod;

// Create a pricebook entry for custom pricebook
PricebookEntry pbe2 = new PricebookEntry(Pricebook2Id=pb.Id, Product2Id=prod.Id,
IsActive=true, CurrencyIsoCode='ARS', UnitPrice=100,

  UseStandardPrice=false);

insert pbe2;

test.startTest();

delete prod;

test.stopTest();

}
}

 


When I run this test class, I get this error message:

 

 Insert failed. First exception on row 0; first error: STANDARD_PRICE_NOT_DEFINED, No standard price defined for this product: []

 

In the line: insert pbe2;

 

 Can someone understand why this is happening? Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
ReidCReidC

All Answers

streetstreet

Have u got any solution....as im facing the same issue.

vijaymindvijaymind

you can make a query on procebook2  because there is always a standard pricebook .

While creating a pricebook you can put isStandard=true but that is not writable field. And while running test this pricebook must be isStandard = true 

 

Pricebook2 p =[Select p.Id, p.Name from Pricebook2 p where isActive=true and isStandard=true Limit 1]; 

 

Thanks

SalesForce China beginnersSalesForce China beginners

   Hello, senior, and I met above problem

         'No standard price defined for this product',
  I try to use

        'Pricebook2 pricebook = [Select p.I d, p.N ame from Pricebook2 p where isActive = true and isStandard = true Limit 1];           'code for object, but called the' List has no rows for assignment to SObject '

 mistakes don't know what to do, hope to get solutions thank

vijaymindvijaymind

Hi ..

Your Standard Price Book is not active . if you will query by removing filter isActive=true ....

You will get the  Standard Price Book ...which will not be active , make that active and put the isActive filter again .

 

 

Thanks

 

 

SalesForce China beginnersSalesForce China beginners
Sorry, the teacher, I am a beginner, not seem to understand your meaning. I will isActive = true after removed Pricebook2 pricebook = [Select p.I d, p.N ame from Pricebook2 p where isStandard = true Limit 1]; Or display error List has no rows for assignment to SObject ??ܰ??ʾ?????????????˾????2012-06-25??ʽ??Ǩ?????????г??????·118?? ???ִ̾???(??ó?Ŷ??Ͻ?)17??A1H2 WORK WITH YOU LIKE FRIENDS ---------------------------------------------------------------------------- ------------------------------------ Lurry Kong (?׵???) | ??????????ֹ?˾?Ƽ?????ҵ???з????? ??վ??http://www.frensworkz.com | ?ٷ?΢???? http://t.sina.com.cn/frensworkz ?ֻ?13717952706 | ???䣺 lurrykong@frensworkz.com | MSN??lurrybookTing@hotmail.com cid:image002.jpg@01CCEB23.E8D5A500
vijaymindvijaymind

I am not sure what exactly is going but can you make sure that your Standard Price Book is Active ?

 

Check by clicking on Procuct Tab -- > I=Then Below of the page is Maintenance Section click on Manage PriceBook -- > Click on Activate Link if Standard Price Book is fall under the Inactive Price Book Section .

And make the same query including both filter isActive and isStandard as well .

 

Hope this would help to resolve your issue .

SalesForce China beginnersSalesForce China beginners
Hello teacher, I am running 'Pricebook2 pricebook = [Select p.I d, p.N ame from Pricebook2 p where isActive = true and isStandard = true Limit 1]; ' in the "salesforce. Schema", but can find out data, it is not that isActive = true? And, I in test class of how to make sure that Standard Price Book is Active?????? ??ܰ??ʾ?????????????˾????2012-06-25??ʽ??Ǩ?????????г??????·118?? ???ִ̾???(??ó?Ŷ??Ͻ?)17??A1H2 WORK WITH YOU LIKE FRIENDS ---------------------------------------------------------------------------- ------------------------------------ Lurry Kong (?׵???) | ??????????ֹ?˾?Ƽ?????ҵ???з????? ??վ??http://www.frensworkz.com | ?ٷ?΢???? http://t.sina.com.cn/frensworkz ?ֻ?13717952706 | ???䣺 lurrykong@frensworkz.com | MSN??lurrybookTing@hotmail.com cid:image002.jpg@01CCEB23.E8D5A500
vijaymindvijaymind

Use system log or Apex Explorer to make the same query . First Do your price book active as I suggested you the steps . 

SalesForce China beginnersSalesForce China beginners
The teacher, I now run "Select p.I d, p.N ame from Pricebook2 p where isActive = true and isStandard = true Limit 1" statements can be in "salesforce. Schema" obtained data such as a screenshot. That does not means that make sure that Standard Price Book is Active?????? But, in the test class, is could not take data, ah, don't know why. QQ??ͼ20110724200302.png ??ܰ??ʾ?????????????˾????2012-06-25??ʽ??Ǩ?????????г??????·118?? ???ִ̾???(??ó?Ŷ??Ͻ?)17??A1H2 WORK WITH YOU LIKE FRIENDS ---------------------------------------------------------------------------- ------------------------------------ Lurry Kong (?׵???) | ??????????ֹ?˾?Ƽ?????ҵ???з????? ??վ??http://www.frensworkz.com | ?ٷ?΢???? http://t.sina.com.cn/frensworkz ?ֻ?13717952706 | ???䣺 lurrykong@frensworkz.com | MSN??lurrybookTing@hotmail.com cid:image002.jpg@01CCEB23.E8D5A500
ReidCReidC
This was selected as the best answer
kishore64kishore64
Hi vijaymind ji,
 
       I am also facing the same problem what the discussion is going on . I am updated what you said i mean path way like -------Check by clicking on Procuct Tab -- > I=Then Below of the page is Maintenance Section click on Manage PriceBook -- > Click on Activate Link if Standard Price Book is fall under the Inactive Price Book Section .

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.