1

Probably dumb question, but I'm in cognitive dissonance. I want to create ContractLineItem from Account's Assets. I go to setup=>Contract line items and check fields. There's a lookup on Product2. ContractLineItem Fields

I've tried to assign ContractLineItem.Product2 but on compile it says that "Incorrect Product2 field for sObject...". I went to workbench and, to my surprise, didn't find the product2Field here. Workbench

I've tried to create a ContractLineItem record without Product2 reference and it requires PriceBookEntry from me. First question is - how is it possible that I have a product2 field in setup, but I don't see it in workbench? Second - how to get correct priceBookEntry? The only way I see is to parse priceBookEntries for the Product and then compare prices from priceBookEntry with AssetPrice. If equals - assign this priceBookEntry to ContractLineItem.

Thank you in advance!

2 Answers 2

1

The SOAP API guide shows fields for the ContractLineItem records .Its clear that you need priceBookEntryId to associate and there is no way to associate to Product2 .

A product2 can have multiple pricebookEntry records depending on the number of pricebook you have defined .

Hence a contract line item can have multiple records for a single Product depending on the PriceBook .

If you have just one pricebook then that will be your default pricebook and you can query for the pricebookEntry with default pricebookId and Product2Id and assoicate that to the contractLineItem .

If you want multiple associations ,then you can query for all the pricebookEntries with given Product2 Id and associate with the ContractLineItem .

2
  • Thank you, understood the logic. But still two surprising things: 1. How did they do that?2.For other Items(QuoteLineItem, OpportunityLineItem) there're both fields - Product2Id and PriceBookEntryId. Only for this item there's a...fake Product2Id field.
    – EvAzi
    Commented Jul 4, 2016 at 15:30
  • Even in QuoteLineItem and OpportunityLineItem they are read only now .PricebookEntry is whats accepted now Commented Jul 4, 2016 at 15:43
0

In the Salesforce model, an Opportunity, Order or ServiceContract is related to one single price book (Pricebook2) : this means that all products added to an Opp, to an Order, or to a ServiceContract are priced with 1 single price book.

So, the key to finding the correct line item is Product Code + Pricebook id (Product2.ProductCode + Pricebook2.Id) : you can easily find the PricebookEntry and add it to the ServiceContract line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .