Question

When I am trying to insert Price Book Entry, I am getting the following error: "No standard price defined for this product"

I followed the following before uploading the data: Upload Standard Pricebook Entry (All products with Standard Price Book, IsActive = true, UseStdPrice = false)

I am not sure about the cause of the issue. The question may not be too clear to understand. Let me know if you need more details.

Was it helpful?

Solution

This is not a programming-related question, I'd call it more of an admin or data-entry problem. Perhaps that's one of reasons the question got low attention. You'd be better off asking it at salesforce.stackexchange.com

First - are you sure you're really using the standard pricebook? Standard pricebook will have the checkbox ticked and will be the oldest one in given organisation:

enter image description here

I have strange feeling that you're in fact trying to upload to custom pricebook. Don't let the name fool you, it might be called "Standard" but if it doesn't have the checkbox...

From help:

The standard price books is a master list of all products, each with its associated default standard price. The standard price book automatically lists all active products that have a standard price. An organization has only one standard price book.

A custom price book is a specialized list of products that can have either standard or custom (list) prices. Custom price books are ideal for offering products at different prices to different market segments. For each custom price book, you determine which products are included, and whether they are offered at your standard price, or at a higher or lower price.

So to "upload some product to standard price book" you have to create a new PricebookEntry record. The process is same for custom and standard pricebooks. I've used Apex instead of Data Loader:

Pricebook2 pBook = [SELECT Id, Name FROM Pricebook2 WHERE IsStandard = true];

Id productId = '01t70000009GfMN'; // my freshly made product that doesn't have standard price (yet) and is not listed in any custom pricebook

PricebookEntry pe = new PricebookEntry(
    Pricebook2Id = pBook.Id,
    Product2Id = productId,
    UnitPrice = 1000,
    IsActive = true
);

insert pe;

Worked like a charm (note that the screenshot "lies" - it says the related list of pricebooks has 0 items even though we've just inserted one. That's because of the standard vs. custom split):

enter image description here

Only after this standard pricebook entry is inserted you can continue to insert the entries for custom pricebooks.

You might find some more useful info at http://www.jeffdouglas.com/download/products-pricebooks.pdf and maybe How do I avoid STANDARD_PRICE_NOT_DEFINED when unit-testing an OpportunityLineItem in Apex v24.0? too (it's unit tests-related but some links there are useful).

OTHER TIPS

Since Summer 14 you can also use

Id pricebookId = Test.getStandardPricebookId();

To get an Id of a Standard Pricebook that you can use on your standard PriceBookEntries.

See https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_test.htm#apex_System_Test_getStandardPricebookId for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top