Pricebook2

Represents a price book that contains the list of products that your organization sells.

Note
In this release, price books are represented by Pricebook2 objects. The Pricebook object is no longer available for use.

Supported Calls

create(), update(), delete(), describeSObjects(), query(), retrieve(), getDeleted(), getUpdated()

Fields

Field Field Type Field Properties Description
Description string Create

Filter

Nillable

Update

Text description of this object.
IsActive boolean Create

Defaulted on create

Filter

Update

Indicates whether this object is active (true) or not (false). Inactive objects are hidden in many areas in the Salesforce.com user interface. You can change this field’s value as often as necessary. Label is Active.
IsDeleted boolean Defaulted on create

Filter

Indicates whether the record has been moved to the Recycle Bin (true) or not (false). Label is Deleted.

IsStandard boolean Defaulted on create

Filter

Indicates whether this object is the standard price book for the organization (true) or not (false). Every organization has one standard price book—all other price books are custom price books.
Name string Create

Filter

idLookup

Update

Required. Name of this object. This field is read-only for the standard price book. Label is Price Book Name.

Usage

A price book is a list of products that your organization sells:

Use this object to query standard and custom price books that have been configured for your organization. A common use of this object is to allow your client application to obtain valid Pricebook2 object IDs for use when configuring PricebookEntry records via the API.

Your client application can perform the following tasks on PricebookEntry objects:

PriceBook2, Product2, and PricebookEntry Relationships

In the API:

These objects are defined only for those organizations that have products enabled as a feature. If the organization does not have the products feature enabled, the Pricebook2 object does not appear in the describeGlobal() call, and you cannot access it via the API.

If you delete a Pricebook2, while a line item references PricebookEntry in the price book, the line item is unaffected, but the Pricebook2 will be archived and unavailable from the API.

For a visual diagram of the relationships between Pricebook2 and other objects, see Product and Schedule Objects.

Price Book Setup

The process of setting up a price book via the API usually means:

  1. Initially loading product data from your organization into Product2 objects (calling create() for each product that you want to add).
  2. For each Product2 object, creating a PricebookEntry that links the Product2 object to the standard Pricebook2. You need to define a standard price for a product at a given currency (if you have multicurrency enabled), before defining a price for that product in the same currency in a custom price book.
  3. Creating a custom Pricebook2.
  4. Querying the Pricebook2 object to obtain their IDs.
  5. For each Pricebook2 object, creating a PricebookEntry for every Product2 that you want to add, specifying unique properties for each PricebookEntry (such as the UnitPrice and CurrencyIsoCode) as needed.

Code Sample

//Create a custom pricebook
Pricebook2 pb = new Pricebook2();
pb.setName("Custom Pricebok");
pb.setIsActive(true);
SaveResult[] saveResults = binding.create(new SObject[]{pb});

// Create a new product
Product2 product = new Product2();
product.setIsActive(true);
product.setName("Product");
SaveResult[] saveResults = binding.create(new SObject[]{product});

// Add product to standard pricebook
QueryResult result = binding.query("select Id from Pricebook2 where isStandard=true");
SObject[] records = result.getRecords();
String stdPbId = records[0].getId();

// Create a pricebook entry for standard pricebook
PricebookEntry pbe = new PricebookEntry();
pbe.setPricebook2Id(stdPbId);
pbe.setProduct2Id(product.Id);
pbe.setIsActive(true);
// set currency isocode if multicurrency  is enabled
pbe.setCurrencyIsoCode("EUR");
pbe.setUnitPrice(100.);
SaveResult[] saveResults = binding.create(new SObject[]{pbe});

// Create a pricebook entry for custom pricebook
PricebookEntry pbe = new PricebookEntry();
pbe.setPricebook2Id(pb.Id);
pbe.setProduct2Id(product.Id);
pbe.setIsActive(true);
// set currency isocode if multicurrency is enabled
pbe.setCurrencyIsoCode("EUR");
pbe.setUnitPrice(100.);
SaveResult[] saveResults = binding.create(new SObject[]{pbe});
© Copyright 2000-2009 salesforce.com, inc. All rights reserved.
Various trademarks held by their respective owners.