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
HVHV 

queryMore()

Hi,

 

I am newbie to SF and per documentation it says that the queryResult returned by the query() call contains a max of 500 records(default).  If more records is needed then a queryMore() call needs to be made.  In my Java client I am not using queryMore() and making the following call where XXX is a number > 500 still fetches me the record.

 

queryResult.getRecords()[XXX]

 

How does it fetch me record where XXX is > 500. ?? Am i missing something here ??

 

Thanks for your responses.

 

 

 

 

Arup SarkarArup Sarkar

Hope this helps. It is there in the documentation.

	public static void querySample() {

		try {
			String soqlQuery = "SELECT FirstName, LastName FROM Contact LIMIT 5000";
			QueryResult result = connection.query(soqlQuery);
			boolean done = false;
			int counter = 0;
			if (result.getSize() > 0) {
				System.out.println("\nLogged-in user can see " +
				result.getRecords().length +
				" contact records."
				);
				while (!done) {
					++counter;
					SObject[] records = result.getRecords();
					for (int i = 0; i < records.length; ++i) {
						Contact con = (Contact) records[i];
						String fName = con.getFirstName();
						String lName = con.getLastName();
						if (fName == null) {
							System.out.println("Contact " + (i + 1) +
							": " + lName
							);
						} else {
							System.out.println("Contact " + (i + 1) + ": " +
							fName + " " + lName
							);
						}
					}
					if (result.isDone()) {
						done = true;
					} else {
						result =
						connection.queryMore(result.getQueryLocator());
					}
				}
			} else {
				System.out.println("No records found.");
			}
			System.out.println("\nQuery succesfully executed. Records fetched. " + counter);
		} catch (ConnectionException ce) {
			ce.printStackTrace();
		}

	}	

 

Arup SarkarArup Sarkar

You can remove the limit of 5000, it will fetch all records.