- Query()
- QueryResult = sforce.connection.query(string queryString);
- QueryMore()
- QueryResult = sforce.connection.query(QueryLocator queryLocator);
Executes a query against the specified object and returns data that matches the specified criteria.
QueryResult has following 4 properties:
- queryLocator
- done
- records
- size
Ponits to remember
- Default query result size = 500 rows
- If the query results exceed 500 rows, queryMore() call and a server-side cursor(queryLocator) to retrieve additional rows in 500-row chunks.
- You can increase the default size up to 2,000 in the QueryOptions header.
- connection.setQueryOptions(250);
queryMore() and queryLocator
- var result = sforce.connection.query("select name, id from account");
- var queryMoreFlag = true;
- while (queryMoreFlag) {
- var records = result.getArray("records");
- for (var i = 0; i < records.length; i++) {
- //process records[i]
- }
- if (result.getBoolean("done")) {
- queryMoreFlag = false;
- } else {
- result = sforce.connection.queryMore(result.queryLocator);
- }
- }
QueryResultIterator()
The AJAX Toolkit provides the QueryResultIterator object so that you can easily iterate through results without invoking queryMore and queryLocator.
- var result = sforce.connection.query("select id, name from account");
- var it = new sforce.QueryResultIterator(result);
- while (it.hasNext()) {
- var account = it.next();
- sforce.debug.log(account.Name);
- }
Quick Link to parent document: Working with the AJAX Toolkit
No comments:
Post a Comment
Thank you for visiting. Your comments are highly appreciated.