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
David Bailey 16David Bailey 16 

Where Can This Understanding Query Results Sample Code Be Run?

In this Understanding Query Results page:
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_relationships_query_results.htm

There is a code sample with a querySample() method and a printContacts() method.  Presuming that the code is intended to be actually tried out, how is it supposed to be run?  And what language is it written in?  It doesn't appear to be Apex, judging from the use of 'int' instead of 'Integer' as the integer type, and the slew of other compile errors thrown.

I took a 'side trip' from my last Trailhead Challenge to research subqueries for parent-to-child relationships (which this sample alleges to demonstrate) and would like to run this code to get a better understanding of this topic.  Every other code sample I've encountered thus far runs without generating compile errors in the Execute Anonymous Window of the Apex Developer Console.  I'm surprised and perplexed that this sample is different!
 
Best Answer chosen by David Bailey 16
Prateek Singh SengarPrateek Singh Sengar
Hi David,
For getting start with java please refer to the below article
https://developer.salesforce.com/page/Introduction_to_the_Force.com_Web_Services_Connector

You will have to build an enterprise or partner wsc using force.com webservice connector. Its an open source project hosted at github.

You can find some additional information at
http://www.asagarwal.com/2398/step-by-step-guide-to-get-started-with-salesforce-soap-api-using-java

All Answers

Prateek Singh SengarPrateek Singh Sengar
Hi David,
The sample code you are refering is written in java. Inorder to execute this you will have to consume enterprise or partner wsdl in java establish connection and then execute this code. However if you want to see the behavior of child queries in apex you can try the following
 
SELECT Name,
  (
    SELECT LastName
    FROM Contacts
  )
FROM Account

You can place this query in your developer console's query editor and see the output. You can add limit filter to restrict the number of records it displays as well.

For processing the records obtained by parent-child query you can try something like
 
//Run a parent-child query with your condition, i have used limit to limit to number of records

List<Account> accList = [SELECT Name,  ( SELECT LastName  FROM Contacts ) FROM Account limit 10];

for(Account acc: accList)
{
List<Contact> contList = acc.Contacts;

/*
* You can run another loop to traverse through contact list
*/

}

Hope this answers your query.
David Bailey 16David Bailey 16
Dear Prateek,

Thank you very much for your reply.  I have already read through the Understanding Query Relults, and I have also run a parent-to-child query in my last Controlling Processes with Queueable Apex Trailhead Challenge.  Therefore I think I understand the basics of the syntax involved.  But, now I want to actually run the sample "Java" code in the post.  As I mentioned above, everything I've seen prior to this has been written in Apex.  So, are you aware of a link or a tutorial that will explain to me exactly how to "consume an enterprise or partner wsdl in Java to establish a connection to execute this code"?  I think I have heard about this somewhere before, but I do not know where the resources for learning about it reside in SFDC.  Again, thanks,

David
Prateek Singh SengarPrateek Singh Sengar
Hi David,
For getting start with java please refer to the below article
https://developer.salesforce.com/page/Introduction_to_the_Force.com_Web_Services_Connector

You will have to build an enterprise or partner wsc using force.com webservice connector. Its an open source project hosted at github.

You can find some additional information at
http://www.asagarwal.com/2398/step-by-step-guide-to-get-started-with-salesforce-soap-api-using-java
This was selected as the best answer
David Bailey 16David Bailey 16
Hey Prateek,

I went through the article/post named "Introduction to the Force.com Web Services Connector".  It required installing Java 8, WSC, and Apache Maven.  I created WSDLs for enterprise, partner, and metatada APIs, and the JAR for them ("force-wsc-38.0.0-uber.jar").  I installed Eclipse (Neon) and ran the Java sample code.  The enterprise and partner Java code ran just fine.  The metadata Java code generated two compiler errors:

Line 54: AsyncResult[] ars = metadataConnection.create(new CustomObject[] { co });
- The method create(CustomObject[]) is undefined for the type MetadataConnection

Line 72: arsStatus = metadataConnection.checkStatus(ids);
- The method checkStatus(String[]) is undefined for the type MetadataConnection

I tried to contact the author of the article/post, Jeff Douglas, but got no response.  By the way, to you know him, or know his email address?

Anyway, an earlier response regarding these same errors said the wsc-31.jar or wsc-32.jar might fix these errors, but I do not know if it is possible to create a previous version of the wsx-XX.jar file.  The current wsc jar version is wsc-38.jar.  The article only gives instructions for generating the current version.  Do you know if its possible to generate a previous version, and if so how to do it?

Cheers,

David