Pricebook2

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

Note

Price books are represented by Pricebook2 objects. As of API version 8.0, the Pricebook object is no longer available. Requests containing Pricebook are refused, and responses do not contain the Pricebook object.

Supported Calls

create(), delete(), describeLayout(), describeSObjects(), getDeleted(), getUpdated(), query(), retrieve(), search(), undelete(), update(), upsert()

Fields

Field Details
Description
Type
string
Properties
Create, Filter, Group, Nillable, Sort, Update
Description
Text description of the price book.
IsActive
Type
boolean
Properties
Create, Defaulted on create, Filter, Group, Sort, Update
Description
Indicates whether the price book is active (true) or not (false). Inactive price books are hidden in many areas in the user interface. You can change this field’s value as often as necessary. Label is Active.
IsArchived
Type
boolean
Properties
Defaulted on create, Filter, Group, Sort
Description

Indicates whether the price book has been archived (true) or not (false). This field is read only.

IsDeleted
Type
boolean
Properties
Defaulted on create, Filter
Description
Indicates whether the price book has been moved to the Recycle Bin (true) or not (false). Label is Deleted.
IsStandard
Type
boolean
Properties
Defaulted on create, Filter, Group, Sort
Description
Indicates whether the price book is the standard price book for the org (true) or not (false). Every org has one standard price book—all other price books are custom price books.
Name
Type
string
Properties
Create, Filter, Group, Sort, Update
Description
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 org sells.

Use this object to query standard and custom price books that have been configured for your org. 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 orgs that have products enabled as a feature. If the org doesn’t have the products feature enabled, the Pricebook2 object doesn’t appear in the describeGlobal() call, and you can’t 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 is 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. Load product data into Product2 records (creating one Product2 record for each product that you want to add).
  2. For each Product2 record, create a PricebookEntry that links the Product2 record 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. Create a Pricebook2 record to represent a custom price book.
  4. For each Pricebook2 record, 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—Java

public void pricebookSample() {
  try {
    //Create a custom pricebook
    Pricebook2 pb = new Pricebook2();
    pb.setName("Custom Pricebok");
    pb.setIsActive(true);
    SaveResult[] saveResults = connection.create(new SObject[]{pb});
    pb.setId(saveResults[0].getId());

    // Create a new product
    Product2 product = new Product2();
    product.setIsActive(true);
    product.setName("Product");
    saveResults = connection.create(new SObject[]{product});
    product.setId(saveResults[0].getId());
    
    // Add product to standard pricebook
    QueryResult result = connection.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.getId());
    pbe.setIsActive(true);
    pbe.setUnitPrice(100.0);
    saveResults = connection.create(new SObject[]{pbe});
    
    // Create a pricebook entry for custom pricebook
    pbe = new PricebookEntry();
    pbe.setPricebook2Id(pb.getId());
    pbe.setProduct2Id(product.getId());
    pbe.setIsActive(true);
    pbe.setUnitPrice(100.0);
    saveResults = connection.create(new SObject[]{pbe});
  } catch (ConnectionException ce) {
    ce.printStackTrace();
  }
}

See Also