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

Commit 6f9efca

Browse files
author
Pat Patterson
committed
Merge branch 'master' of github-sfdc:developerforce/Force.com-JavaScript-REST-Toolkit
2 parents 3d99e4b + 75c6fbf commit 6f9efca

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

forcetk.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,10 @@ if (forcetk.Client === undefined) {
249249
* @param [error=null] function to which jqXHR will be passed in case of error
250250
* @param [method="GET"] HTTP method for call
251251
* @param [payload=null] payload for POST/PATCH etc
252+
* @param [paramMap={}] parameters to send as header values for POST/PATCH etc
253+
* @param [retry] specifies whether to retry on error
252254
*/
253-
forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, retry) {
255+
forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, paramMap, retry) {
254256
var that = this;
255257
var url = this.instanceUrl + '/services/apexrest' + path;
256258

@@ -268,7 +270,7 @@ if (forcetk.Client === undefined) {
268270
that.refreshAccessToken(function(oauthResponse) {
269271
that.setSessionToken(oauthResponse.access_token, null,
270272
oauthResponse.instance_url);
271-
that.ajax(path, callback, error, method, payload, true);
273+
that.apexrest(path, callback, error, method, payload, paramMap, true);
272274
},
273275
error);
274276
} else {
@@ -280,6 +282,13 @@ if (forcetk.Client === undefined) {
280282
if (that.proxyUrl !== null) {
281283
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
282284
}
285+
//Add any custom headers
286+
if (paramMap === null) {
287+
paramMap = {};
288+
}
289+
for (paramName in paramMap) {
290+
xhr.setRequestHeader(paramName, paramMap[paramName]);
291+
}
283292
xhr.setRequestHeader(that.authzHeader, "OAuth " + that.sessionId);
284293
xhr.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
285294
}
@@ -430,6 +439,30 @@ if (forcetk.Client === undefined) {
430439
this.ajax('/' + this.apiVersion + '/query?q=' + escape(soql)
431440
, callback, error);
432441
}
442+
443+
/*
444+
* Queries the next set of records based on pagination.
445+
* <p>This should be used if performing a query that retrieves more than can be returned
446+
* in accordance with http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_query.htm</p>
447+
* <p>Ex: forcetkClient.queryMore( successResponse.nextRecordsUrl, successHandler, failureHandler )</p>
448+
*
449+
* @param url - the url retrieved from nextRecordsUrl or prevRecordsUrl
450+
* @param callback function to which response will be passed
451+
* @param [error=null] function to which jqXHR will be passed in case of error
452+
*/
453+
forcetk.Client.prototype.queryMore = function( url, callback, error ){
454+
//-- ajax call adds on services/data to the url call, so only send the url after
455+
var serviceData = "services/data";
456+
var index = url.indexOf( serviceData );
457+
458+
if( index > -1 ){
459+
url = url.substr( index + serviceData.length );
460+
} else {
461+
//-- leave alone
462+
}
463+
464+
this.ajax( url, callback, error );
465+
}
433466

434467
/*
435468
* Executes the specified SOSL search.

0 commit comments

Comments
 (0)