Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit 5a4f31b

Browse files
committed
UPDATE: add in a queryMore function to the forcetk to allow simpler handling of the rest pagination urls.
Calling forcetkClient.ajax doesn't quite work as ajax adds on 'services/data' to the request, which is already present from successResponse.nextRecordsUrl. Signed-off-by: Paul Roth <paulroth3d@gmail.com>
1 parent 026cfcc commit 5a4f31b

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

forcetk.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,31 @@ if (forcetk.Client === undefined) {
430430
this.ajax('/' + this.apiVersion + '/query?q=' + escape(soql)
431431
, callback, error);
432432
}
433+
434+
/*
435+
* Queries the next set of records based on pagination.
436+
* <p>This should be used if performing a query that retrieves more than can be returned
437+
* in accordance with http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_query.htm</p>
438+
* <p>Ex: forcetkClient.queryMore( successResponse.nextRecordsUrl, successHandler, failureHandler )</p>
439+
*
440+
* @param url - the url retrieved from nextRecordsUrl or prevRecordsUrl
441+
* @param callback function to which response will be passed
442+
* @param [error=null] function to which jqXHR will be passed in case of error
443+
*/
444+
forcetk.Client.prototype.queryMore = function( url, callback, error ){
445+
446+
//-- ajax call adds on services/data to the url call, so only send the url after
447+
var serviceData = "services/data";
448+
var index = url.indexOf( serviceData );
449+
450+
if( index > -1 ){
451+
url = url.substr( index + serviceData.length );
452+
} else {
453+
//-- leave alone
454+
}
455+
456+
this.ajax( url, callback, error );
457+
}
433458

434459
/*
435460
* Executes the specified SOSL search.

0 commit comments

Comments
 (0)