I have a SOQL query that looks like this:
SELECT Id, OwnerId, IsDeleted, AboutThirtyFieldsTotal__c, ...
(SELECT Id, IsDeleted, OverFiftyFields__c, ...
FROM Borrowers__r )
FROM Loan__c WHERE LSC__c = '0051F00000ocJMdQAM'
ORDER BY CreatedDate LIMIT 200
The entire query is about 1,500 characters long.
When I run this query directly (by selecting it in VS Code and executing it with the command pallet) I get the correct result, with columns for Borrowers__r.FirstName__c
with multiple rows for each of the related records.
If I run the exact same query from within Database.query
, I don't get the related data, only the data from Loan__c
with no data after the last field in the outer SELECT
?
Why do I get related data when I directly execute the SOQL but not when it's executed by Apex?
System.debug(LoanController.getLoans('0051F00000ocJMdQAM', 'lsc'));
I execute this by highlighting it and using "Execute Anonymous Apex" in the command palette. It is this line that doesn't have the related records. However, withingetLoans
ISystem.debug(query);
, and when I highlight that query and use the command palette to "Execute SOQL," I do get the related records.