0

I tried the following SOQL and tried to use the ProductCode but getting the error as given below.

for(PriceBookEntry pbe: [Select p.UseStandardPrice, p.UnitPrice, p.ProductCode, p.Product2Id, p.Pricebook2Id, p.Name, p.Id From PricebookEntry p where p.ProductCode in : lstProdCode]) {
    mapPbe.put(p.ProductCode,pbe);
}

Compilation error: Variable does not exist: p.ProductCode

Any suggestions please. Thanks.

1 Answer 1

5

When iterating through your list you are using p.ProductCode to access the field but your loop variable is called pbe.

You should use pbe.ProductCode instead.

Altenatively you can take the ProductCode value from the Product2 record which is related to your PricebookEntry. Although there is no real advantage to using this approach.

If you want to do it, then change the following:

p.ProductCode

To this, in both your query and when you add to your map:

p.Product2.ProductCode
3
  • Sometimes you just need an another set of eyes ;)
    – EricSSH
    Commented Feb 10, 2015 at 18:28
  • @Alex you first reply has worked fine for me. If you rollback i will mark that as an answer. Thanks.
    – Bforce
    Commented Feb 10, 2015 at 19:09
  • @BaskaranS I've edited this answer to include my other one, the previous answer contained some false statements, plus I believe this is the better answer as there is no advantage to using Product2.ProductCode as the ProductCode field on PricebookEntry will always contain the same value. Commented Feb 11, 2015 at 9:21

You must log in to answer this question.

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