Trying to update an OpportunityLineItem, but need to be able to look for that particular product in the opportunity.
Problem:
SOQL is using the List Price from the product but from a different
opportunity
Error:
in (SELECT OpportunityId FROM OpportunityLineItem)LIMIT 1
^ ERROR at Row:4:Column:103 The inner and outer selects should not be on the same object type
I understand what the error is, but can't figure out a solution to get what I need. Any ideas?
SOQL
OpportunityLineItem optLIProductB = [SELECT OpportunityId, Opportunity.Pricebook2Id, Name, ProductCode , PricebookEntryId, Quantity, UnitPrice
FROM OpportunityLineItem
WHERE ProductCode = '1b0000'
AND OpportunityId in (SELECT OpportunityId FROM OpportunityLineItem)LIMIT 1];
Best Answer
You need to query by a particular id, or a list of ids, instead of all available ids. You can use a bind to provide an apex variable to a query for use in a filter.
From the Using Apex Variables in SOQL:
You can also use a
Id
or aList<Id>
.This is a general example on how to use these variables in queries. Try to modify your code to use these, and either edit your question, or ask a new question if you encounter issues with your code.