Conceptually, there is one Standard Pricebook and there are many custom Pricebooks. This allows you to do the following:
- For SKU xyz, the standard pricebook price could be $10.00
- For the same SKU xyz, on the pricebook called Commercial, the price is $10.00
- For the same SKU xyz, on the pricebook called US Government, the price is only $8.00
When you create a pricebookEntry for the junction between Product2 and Standard Pricebook, set useStandardPricebook
to false
. All pricebookEntries on standard Pricebook have useStandardPrice
= false
When you create a pricebookEntry for the junction between Product2 xyz and Pricebook US Government, set useStandardPricebook
to false
and set unitPrice to 8.00.
On custom pricebook called 'Commercial' where SKU xyz is $10.00, then when you create a pricebookEntry for the junction between Product2 xyz and Pricebook Commercial, set useStandardPricebook
to true
and set unitPrice to 10.00.
In effect, your updates to PricebookEntry are mimicing the SFDC Force.com user interface where you define standard pricebook prices for a Product and then, if you use custom pricebooks, you can choose to use the standard price or override the standard price, just for that pricebook.
Don't forget that all pricebook entries must be inserted against the Standard pricebook before you can insert pricebookEntries on custom pricebooks.
Ok, I am to lazy to wait for answer ;/
It will work, but before adding product to custom PriceBook it must have Standard Price.
In other words it must be added to Standard PriceBook.
Best Answer
Anu --
PricebookEntry
SObject which is a junction betweenPricebook2
andProduct2
.PricebookEntry
defines the product's list price for a given currency on that pricebook. That is, for a given product and currency, there will be 1+ PricebookEntries - one for the standard pricebook and additional ones for each custom pricebook containing that product.Your controller will need to a) locate the ID of the standard Pricebook2 (there is only one) and then b) query the PricebookEntry table using as search filters : standard pricebook ID, Product2 ID, and currencyIsoCode (note: a and b could be combined in one query)
if this finds a record, then there is an active standard price for that currency/product
A useful reference is the SFDC Objects doc - http://www.salesforce.com/us/developer/docs/object_reference/index.htm
With this as background, you should be able to adjust your controller to only display products that exist on the standard pricebook, or show better error messages, or whatever your application needs