0

I am trying to query Opportunities which have a Product matching certain criteria on, something like below:

SELECT Name 
FROM Opportunity 
WHERE type != 'renewal' 
  AND Id IN (SELECT OpportunityId 
             FROM OpportunityLineItem 
             WHERE pricebookentry.product2.custom__c = 'value') 

While the above doesn't cause an error no rows are returned. Is this possible or is my soql not formed correctly?

Edit: Splitting the SOQLS, the Opportunity part returns rows as expected. The OpportunityLineItem part doesn't:

SELECT OpportunityId
FROM OpportunityLineItem
WHERE pricebookentry.product2.custom__c = 'value'

So I believe I am doing something wrong with the OLI to Product part: pricebookentry.product2.custom__c

  • 1
    Did you try both query ("Select ... From Opportunity WHERE Type" ... and "SELECT FROM OppLineItem ...") ? Did they return something ? – MMT Feb 25 '15 at 14:52
  • Yes I've added some more detail to my question. – Girbot Feb 25 '15 at 14:56
  • 1
    Your OLI query looks ok. Do you have any products with custom__c = 'value'? and do you have any added to an opportunity? As nothing is returned from your OLI query then I would suggest your filter is causing the problem. – Richard Durrant Feb 25 '15 at 15:41
1

It appears the issue was elsewhere in the class and not with the SOQL in my post. It is working as intended now.

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.