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

  • 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 Jul 16 '14 at 19:04
  • Yes! this is the answer! – Eric Luu Jul 16 '14 at 21:43
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

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.