You need to sign in to do that
Don't have an account?
SalesForce 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
All Answers
Either your record doesn't exist or search criteria are wrong.
Hi
you query is correct.
i think your standard price is not active. Make Active standard pricebook.
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
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;