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
SalesForce China beginnersSalesForce China beginners 

No standard price defined for this product New problems

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

Best Answer chosen by Admin (Salesforce Developers) 
SalesForce China beginnersSalesForce China beginners
Thank you, the problem successfully resolved Reason in the API to 24.0 or 24.0 later, if want to inquires the data to test system, must be in the first line join @ isTest (SeeAllData = true) ??ܰ??ʾ?????????????˾????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

All Answers

stcforcestcforce

Either your record doesn't exist or search criteria are wrong.

SalesForce China beginnersSalesForce China beginners
QQ??ͼ20120813125828.png Teacher, I could use the same records to find out the query, however, is in the background could not take records, don't know why. Look at my screenshots ??ܰ??ʾ?????????????˾????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
sivaextsivaext

Hi 

 

you query is correct. 

 i think your standard price is not active. Make Active standard pricebook.

 

 

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]; 'statements 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
asish1989asish1989

Hi 

 You have to define product in PriceBookEntry object .

 

 

So there is a trigger which may help you...

 

trigger AutoPopulatePricebookEntry on Product2 (after insert) {

sObject s = [select ID from Pricebook2 where IsStandard = TRUE];

for (Product2 newProduct: Trigger.new) {

PricebookEntry z = new PricebookEntry(Pricebook2Id=s.ID,Product2Id=newProduct.ID, UnitPrice=0.00, IsActive=TRUE, UseStandardPrice=FALSE);
insert z;

}

}

 

Did this post solve your issue ..if so please mark it solved so that others get benifits..

 

 

Thanks

asish

 

 

SalesForce China beginnersSalesForce China beginners

 

 

I this is to write test class ah only always error occurs

List has no rows for assignment to SObject

 

 

 

 

Product2 product=new Product2();
product.Product_Code__c='dl7887';
product.Name='玩具火箭';
product.Description='玩具火箭 测试数据';
insert product;

sObject s = [select ID from Pricebook2 where IsStandard = TRUE];

PricebookEntry pricebookentry=new PricebookEntry();
pricebookentry.Product2Id=product.Id;
pricebookentry.Pricebook2Id=s.Id;
pricebookentry.UnitPrice=100.00;
pricebookentry.UseStandardPrice=false;
insert pricebookentry;

SalesForce China beginnersSalesForce China beginners
Thank you, the problem successfully resolved Reason in the API to 24.0 or 24.0 later, if want to inquires the data to test system, must be in the first line join @ isTest (SeeAllData = true) ??ܰ??ʾ?????????????˾????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
This was selected as the best answer