In my viualforce page I am adding products - I don't want to hardcode the references to the products, I want the button to pull the proper product per Opportunity. Why does my line not work to find the proper pricebook entry? The method:
public PageReference AddJuiceProduct (){
Opportunity TheOpp = (Opportunity)sc.GetRecord();
NewLineItem.OpportunityId=TheOpp.id;
NewLineItem.PricebookEntryId=[select id from PricebookEntry where name =: 'Juice' and Pricebook2id=:op.Pricebook2Id].id;
NewLineItem.Quantity=1;
ETC code...
insert NewLineItem;
If I hardcode the reference to the product the insert works. Example:
NewLineItem.PricebookEntryId='123456798798794654';
Why doesn't this query work? thanks!
NewLineItem.PricebookEntryId=[select id from PricebookEntry
where name =: 'Juice'
and Pricebook2id=:op.Pricebook2Id].id;
Name
is'Juice'
?