5

Currently I'm having issue saving my code:

public static void myMethodMyMethod(Map<Id,OpportunityLineItem> OLIs, String action){

        for(OpportunityLineItem oli:OLIs.values()){
            system.debug('oli.ProductCode '  + oli.ProductCode);
        }

}

I keep getting this error: Invalid field ProductCode for SObject OpportunityLineItem

I was able to print out other fields information from sObject oli (i.e. OpportunityId, UnitPrice, etc). For some reason ProductCode does not work...

Any advice?

Thank you, Eric

2
  • 3
    1) Check your API version of the class 2) Can you try oli.product2.productcode. As per docs salesforce.com/us/developer/docs/api/Content/… ProductCode :This read-only field is available in API version 30.0 and later. It references the value in the ProductCode field of the related Product2 record.
    – Rao
    Commented Jul 16, 2014 at 19:04
  • Yes! this is the answer!
    – Eric Luu
    Commented Jul 16, 2014 at 21:43

1 Answer 1

3

1) Check your API version of the class

2) Can you try oli.product2.productcode.

As per docs

https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_opportunitylineitem.htm

ProductCode :This read-only field is available in API version 30.0 and later. It references the value in the ProductCode field of the related Product2 record

You must log in to answer this question.

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