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
QueballQueball 

Return value of QueryResult.getRecords(). (Partner 6)

Hello all,

I have a question on the return value of a call to QueryResult.getRecords() where the query did not have any returned records. From the documentation we would get in return an instantiated SObject array with length of 0. Is there ever a possibility that this function will return null? Example below.

SoapBinding soapBinding; // Please assume that this is already logged-in.
QueryResult queryResult;

queryResult = soapBinding.query(queryString);
SObject[] sObjects = queryResult.getRecords();

if(sObjects != null){ if(sObject.length > 0){
// do operations on the sObject
}
}

Thanks for the help
SuperfellSuperfell
When an empty array is returned, most toolkits will return null rather than an empty array.
DevAngelDevAngel
The queryResult also has a size field that indicates how many records matched the query. If the size == 0 then you don't need to even access the getRecords() array.