Closed pranayjswl007 closed 5 years ago
Try
public List<Account> selectByIdWithCurrentResidences(Set<Id> idSet){
// Query Factory for this Selector (Account)
fflib_QueryFactory accountQueryFactory = newQueryFactory();
accountQueryFactory.setCondition('Id IN :idSet');
fflib_QueryFactory residenceQueryFactory =
accountQueryFactory.subSelectQuery('Residences__r')
.setCondition('Is_Current__c = true')
.setLimit(1);
return Database.query( accountQueryFactory.toSOQL() );
}
I have a custom object(Residence__c) which has lookup relationship to Account, Now I am trying to use FinancialForce sObjectSelector to Querry Account with Residences and have few filters on residences.
I created the first Selector for Residences
Now creating a Selector for Account
As you can see in my residenceQueryFactory which I got from ResidenceSelector I am adding Limit and conditions. And as its a subquery I added it to parent accountQueryFactory.
Generated SOQL:
SELECT FirstName, LastName, PersonBirthdate, (SELECT Id, Name FROM Residences__r ORDER BY Name ASC NULLS FIRST ) FROM Account WHERE Id IN :idSet ORDER BY Name ASC NULLS FIRST
I expected the subquery filter and Limits to be applied on subquery, but they are not as seen in System.debug, Can someone point me what bit I am doing wrong?