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
TesterInSkyTesterInSky 

question on implementing Relationship Queries by using JAVA

I am now trying to implement Relationship Queries by using JAVA on my side, but encountering some problems.

I did the following test:
In a clear Salesforce (SF) database, which have no TestParent__c or TestChild__c sObjects in it:
1. Create a TestParent__c sObject (which is a custom sOjbect to simulate the parent object in a relationship query) in my SF database, filling the necessary values;
2. Create more than 300 TestChild__c sObjects (which is a custom sOjbect to simulate the children object related to the parent in a relationship query) in my SF database, filling the necessary values;
3. Then I set the batch size to 200, and do query by using JAVA code. The query string is as follow:
"select id, Company__c, (select Id, ChildName__c from TestChildren__r) from TestParent__c"

After I invoke the ‘query’ SOAP operation at the first time, I noticed that, though there is only one TestParent__c in my SF database, the ‘done’ for the queryResult of TestParent__c is ‘false’, and the ‘queryLocator’ has value ‘01g80000004rjaMAAQ-1’.

So in this situation, I do not only need to call queryMore for the nested TestChildren__r query (which actually should return 300 sObjects but the batch size is 200, so…), but also need to call queryMore for TestParent__c, the original query as well. And the sequence of these two queryMore callings seems to be restricted, that is I HAVE TO call the queryMore for the original query after any other nested queryMore has been called.

And I also noticed one thing, which is though I set the batch size to 200, the count of the data returned in the nested TestChildren__r is not 200, it is 199.

So confirm me with whether the behaviors that I illustrated above are expected. And if the SF is designed in this way, is there any reason for this? Can it provide any special ways to handle the data more convenience?
SuperfellSuperfell
calling queryMore on the outer results will invalidate all the previous cursors for the children, this is by design. remember that batchSize is only a hint, you may or may not get the exact number you ask for. What would you like to be able to do that's more convenient ?