Salesforce's Spring '21 release finally offers Opportunity Product (OpportunityLineItem) lookups, which my organization has been waiting a long time for. However, we're having issues with our implementation, specifically around formula fields.

For some reason, formulas referencing certain standard OpportunityLineItem fields don't validate: ProductCode does not exist error

I've tested with a number of different fields and I've encountered the issue inconsistently. I've found the the following fields error out:

  • Opportunity_Line_Item__r.ProductCode
  • Opportunity_Line_Item__r.Name
  • Opportunity_Line_Item__r.Product2Id (and Product2.*)

But the following do not error out:

  • Opportunity_Line_Item__r.CreatedById
  • Opportunity_Line_Item__r.TotalPrice
  • Opportunity_Line_Item__r.Discount
  • Opportunity_Line_Item__r.Description

Why does the OpportunityLineItem lookup appear to be behaving differently in regards to formula field access?

  • can you do Opportunity_Line_Item__r.PricebookEntry.Product2.ProductCode ?
    – cropredy
    Jan 25 at 19:21
  • Yes, that appears to work just fine and is a perfect workaround. Thank you! Any idea on why the standard fields aren't accessible? Jan 25 at 21:39

As a workaround since accessing the Product2 relationship from OpportunityLineItem, QuoteItem, or OrderItem has often given developers trouble is to use the PricebookEntry relationship:

  • Opportunity_Line_Item__r.PricebookEntry.Product2.ProductCode
  • Opportunity_Line_Item__r.PricebookEntry.Product2ID


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.