0

Below is the SOQL query that gets executed successfully in Workbench but unable to save the same query in apex code getting below error.

SELECT Quantity, Product2.ExternalId 
FROM OpportunityLineItem 
Where OpportunityId =: OppId

Apex code snippet

unable to save this in apex as it gives below error

opportunityLineItemList = [SELECT Quantity, Product2.ExternalId 
                           FROM OpportunityLineItem 
                           Where OpportunityId =: OppId];

Error No Such column 'ExternalId' on entity Product2

FLS is been given to the field

8
  • Its working for me..Probably missing the permission.
    – bharath
    Jun 16, 2017 at 10:09
  • 1
    Is your class is having API version 30.0 or higher ? The ID of the related Product2 record. This is a read-only field available in API version 30.0 and later. Jun 16, 2017 at 10:11
  • @bharath Permission is there otherwise it wouldn't have executed in workbench as well.
    – RCS
    Jun 16, 2017 at 10:23
  • @NachiketDeshpande the api version is 36.0
    – RCS
    Jun 16, 2017 at 10:25
  • 1
    Yes it did work after the class was upgraded to version 40.0
    – RCS
    Jun 16, 2017 at 10:37

1 Answer 1

0

Is your class is having API version 30.0 or higher ? The ID of the related Product2 record. This is a read-only field available in API version 30.0 and later.
Ref: OpportunityLineItem

You must log in to answer this question.

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