0

I have a Product Purchase as a parent object of a child object namely Payment. Now, when I run the query below, I am also getting Product Purchase objects which do not have any Payment(s) attached to them. How would I filter this using a COUNT().

$query = "SELECT Id, CreatedDate,
                (SELECT Id, PayPal_Transaction_Id__c, CreatedDate
                FROM Payments__r
                WHERE PayPal_Transaction_Id__c != null),
             Installments__c, Paid__c
             FROM Product_Purchase__c
             WHERE Installments__c > 1
             AND Paid__c = false";

2 Answers 2

0

You can query something like this to get all the Product_Purchase__c which has at list one child.

$query = "SELECT Id, CreatedDate,
                (SELECT Id, PayPal_Transaction_Id__c, CreatedDate
                FROM Payments__r
                WHERE PayPal_Transaction_Id__c != null),
             Installments__c, Paid__c
             FROM Product_Purchase__c
             WHERE Installments__c > 1
             AND Paid__c = false" AND ID IN (SELECT ID, Product_Purchase__c from Payments__C WHERE Product_Purchase__c != '');
0

You can't use Count() in a subquery or as a subquery condition in a WHERE clause. That wouldn't be an option for restructuring your query. See the Force.com SOQL and SOSL Reference | Comparison Operators | Subquery limits: for more (near bottom of the page).

You must log in to answer this question.

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