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

  • Its working for me..Probably missing the permission. – bharath Jun 16 '17 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. – Nachiket Deshpande Jun 16 '17 at 10:11
  • @bharath Permission is there otherwise it wouldn't have executed in workbench as well. – RCS Jun 16 '17 at 10:23
  • @NachiketDeshpande the api version is 36.0 – RCS Jun 16 '17 at 10:25
  • 1
    Yes it did work after the class was upgraded to version 40.0 – RCS Jun 16 '17 at 10:37
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

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.