Skip to content

Commit 02b7f95

Browse files
author
Pat Patterson
committed
Added upsert - closes developerforce#2
1 parent 336aa49 commit 02b7f95

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

forcetk.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,23 @@ if (forcetk.Client === undefined) {
259259
+ '?fields=' + fieldlist, callback, error);
260260
}
261261

262+
/*
263+
* Upsert - creates or updates record of the given type, based on the
264+
* given external Id.
265+
* @param objtype object type; e.g. "Account"
266+
* @param externalIdField external ID field name; e.g. "accountMaster__c"
267+
* @param externalId the record's external ID value
268+
* @param fields an object containing field names and values for
269+
* the record, e.g. {:Name "salesforce.com", :TickerSymbol
270+
* "CRM"}
271+
* @param callback function to which response will be passed
272+
* @param [error=null] function to which jqXHR will be passed in case of error
273+
*/
274+
forcetk.Client.prototype.upsert = function(objtype, externalIdField, externalId, fields, callback, error) {
275+
this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + externalIdField + '/' + externalId
276+
+ '?_HttpMethod=PATCH', callback, error, "POST", JSON.stringify(fields));
277+
}
278+
262279
/*
263280
* Updates field values on a record of the given type.
264281
* @param objtype object type; e.g. "Account"

0 commit comments

Comments
 (0)