function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phuc Nguyen 18Phuc Nguyen 18 

Subquery filter not working

Hello ALl,
I have a controller for a VF page where I am returing fileds from a parent and multiple child records.
Here is the code in the controller
Accountres = [Select Id,(select Amount__c,Fee_Type__c,Invoice__c from Customer__r where Invoice__c = null) from Account where id=:acctId];

The issue I am having is that the criteria for the Customer__r is not working.  If I have 3 customer and 2 of them have an invoice I want only 1 record returned but  Instead I get all 3.  
Thanks,
P
Best Answer chosen by Phuc Nguyen 18
SarvaniSarvani
Hi Phuc,

Did you mean "==" instead of "=" Try this query:
Accountres = [Select Id,(select Amount__c,Fee_Type__c,Invoice__c from Customer__r where Invoice__c == null) from Account where id=:acctId];
Also you can use LIMIT 1 to limit number of records returned from child records.
Accountres = [Select Id,(select Amount__c,Fee_Type__c,Invoice__c from Customer__r where Invoice__c == null LIMIT 1) from Account where id=:acctId];
Hope this help! Please mark as best answer if it does.

Thanks