You need to sign in to do that
Don't have an account?
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!
I posted a more detailed answer over here.
All Answers
Have u got any solution....as im facing the same issue.
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
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
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
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 .
Use system log or Apex Explorer to make the same query . First Do your price book active as I suggested you the steps .
I posted a more detailed answer over here.
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.