1

I want to upsert a Product record using Apex.

When I write:

Product pr = new Product();

It gives an error "Invalid Type: Product".

but when I write

Product2 pr = new Product2();

Then no error occurs.

Can anyone please explain the reason behind this.

  • 7
    A long, long time ago, there was a Product object, along with a PriceBook object. However, it had some design flaws, and so salesforce.com retired it. However, because of their policy for backwards compatibility, they could not directly get rid of this object, nor was there a way to determine which behavior to invoke based on the name alone, so they introduced a new Product2 and Pricebook2. This allowed the old and new objects to coexist side by side. Today, we only use the *2 version of these objects. – sfdcfox Aug 22 '18 at 11:09
  • @sfdcfox thanks for sharing. I don't think we can find it anywhere else. – Tushar Sharma Aug 22 '18 at 11:20
  • @sfdcfox thanks for this helpful information. – Jahnvi Jasani Aug 22 '18 at 11:23
4

Products are represented by Product2 objects. As of API version 8.0, the Product object is no longer available. Requests containing Product are refused, and responses do not contain the Product object.

So You need to use Product2 in your query but the label is Product.

Product2

Represents a product that your org sells. This object has several fields that are used only for quantity and revenue schedules (for example, annuities).

Products are the items and services that you sell to customers. Each product can exist in multiple price books with different prices.

Reference:-

Product object

2

Products is the label while Product2 is the API name. In apex we use API name that's why you have to use Product2 to create a new instance.

Product object is no longer available after API version 8.

Product2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.