diff --git a/BulkAPISampleFiles/delete.csv b/BulkAPISampleFiles/delete.csv
new file mode 100644
index 0000000..9535358
--- /dev/null
+++ b/BulkAPISampleFiles/delete.csv
@@ -0,0 +1,5 @@
+Id
+003E000001DJOfxIAH
+003E000001DJOfyIAH
+003E000001DJOV4IAP
+003E000001DJOV5IAP
\ No newline at end of file
diff --git a/BulkAPISampleFiles/delete.xml b/BulkAPISampleFiles/delete.xml
new file mode 100644
index 0000000..e644728
--- /dev/null
+++ b/BulkAPISampleFiles/delete.xml
@@ -0,0 +1,16 @@
+
+
+
+
+ 003E000001DJOfxIAH
+
+
+ 003E000001DJOfyIAH
+
+
+ 003E000001DJOV4IAP
+
+
+ 003E000001DJOV5IAP
+
+
\ No newline at end of file
diff --git a/BulkAPISampleFiles/insert.csv b/BulkAPISampleFiles/insert.csv
new file mode 100644
index 0000000..31cb26a
--- /dev/null
+++ b/BulkAPISampleFiles/insert.csv
@@ -0,0 +1,3 @@
+FirstName,LastName,Department,Birthdate,Description
+Tom,Jones,Marketing,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast"
+Ian,Dury,R&D,,"World-renowned expert in fuzzy logic design. Influential in technology purchases."
\ No newline at end of file
diff --git a/BulkAPISampleFiles/insert.xml b/BulkAPISampleFiles/insert.xml
new file mode 100644
index 0000000..686ed5a
--- /dev/null
+++ b/BulkAPISampleFiles/insert.xml
@@ -0,0 +1,17 @@
+
+
+
+
+ Tom
+ Jones
+ Marketing
+ 1940-06-07Z
+ Self-described as "the top" branding guru on the West Coast
+
+
+ Ian
+ Dury
+ R&D
+ World-renowned expert in fuzzy logic design. Influential in technology purchases.
+
+
\ No newline at end of file
diff --git a/BulkAPISampleFiles/update.csv b/BulkAPISampleFiles/update.csv
new file mode 100644
index 0000000..230ef1a
--- /dev/null
+++ b/BulkAPISampleFiles/update.csv
@@ -0,0 +1,2 @@
+Id,Title
+003E000001CbzBi,Ninja
\ No newline at end of file
diff --git a/BulkAPISampleFiles/update.xml b/BulkAPISampleFiles/update.xml
new file mode 100644
index 0000000..8574c72
--- /dev/null
+++ b/BulkAPISampleFiles/update.xml
@@ -0,0 +1,8 @@
+
+
+
+
+ 003E000001CbzBi
+ Pirate
+
+
\ No newline at end of file
diff --git a/BulkAPISampleFiles/upsert.csv b/BulkAPISampleFiles/upsert.csv
new file mode 100644
index 0000000..5841c32
--- /dev/null
+++ b/BulkAPISampleFiles/upsert.csv
@@ -0,0 +1,2 @@
+Twitter_Handle__c,Title
+pattest7,Guru
\ No newline at end of file
diff --git a/BulkAPISampleFiles/upsert.xml b/BulkAPISampleFiles/upsert.xml
new file mode 100644
index 0000000..b942d57
--- /dev/null
+++ b/BulkAPISampleFiles/upsert.xml
@@ -0,0 +1,8 @@
+
+
+
+
+ pattest7
+ Pirate
+
+
\ No newline at end of file
diff --git a/BulkTK.md b/BulkTK.md
new file mode 100644
index 0000000..a5eb38f
--- /dev/null
+++ b/BulkTK.md
@@ -0,0 +1,137 @@
+BulkTK: Force.com Bulk API JavaScript Toolkit
+=============================================
+
+This minimal toolkit extends ForceTK to allow JavaScript in web pages to call the [Force.com Bulk API](https://www.salesforce.com/us/developer/docs/api_asynch/).
+
+Background
+==========
+
+The Force.com Bulk API allows asynchronous data access. BulkTK extends ForceTK with methods to create Bulk API jobs, add batches to them, monitor job status and retrieve job results. Control plane XML is parsed to JavaScript objects for ease of use, while data is returned verbatim.
+
+You should familiarize yourself with the [Force.com Bulk API documentation](https://www.salesforce.com/us/developer/docs/api_asynch/), since BulkTK is a relatively thin layer on the raw XML Bulk API.
+
+[bulk.page](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/bulk.page) is a simple Visualforce single page application to demonstrate BulkTK. Try it out in a sandbox or developer edition.
+
+Note that, just like ForceTK, BulkTK is unsupported and supplied as is. It is also currently in a very early stage of development. It appears to work well, but bugs cannot be ruled out, and the interface should not be considered stable.
+
+Dependencies
+============
+
+ * [jquery](http://jquery.com/)
+ * [ForceTK](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit)
+ * [jxon](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/jxon.js) (originally from the [Ratatosk](https://github.com/wireload/Ratatosk) project; this version preserves case in element and attribute names)
+
+Example Usage
+=============
+
+This example focuses on Visualforce. See the [ForceTK documentation](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit) for details on authenticating from an external website, such as a Heroku app, or PhoneGap/Cordova.
+
+First, include BulkTK and its dependencies:
+
+
+
+
+
+
+Now create a ForceTK client:
+
+ var client = new forcetk.Client();
+ client.setSessionToken('{!$Api.Session_ID}');
+
+See the [ForceTK documentation](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit) for details on authenticating from an external website, such as a Heroku app, or PhoneGap/Cordova.
+
+Create a job
+------------
+
+ // See https://www.salesforce.com/us/developer/docs/api_asynch/Content/asynch_api_reference_jobinfo.htm
+ // for details of the JobInfo structure
+
+ // Insert Contact records in CSV format
+ var job = {
+ operation : 'insert',
+ object : 'Contact',
+ contentType : 'CSV'
+ };
+
+ client.createJob(job, function(response) {
+ jobId = response.jobInfo.id;
+ console.log('Job created with id '+jobId+'\n');
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error creating job', jqXHR.responseText);
+ });
+
+Add a batch of records to the job
+---------------------------------
+
+You can add multiple batches to the job; each batch can contain up to 10,000 records. See [batch size and limits](https://www.salesforce.com/us/developer/docs/api_asynch/Content/asynch_api_concepts_limits.htm#batch_size_title) for more details.
+
+ var csvData = "FirstName,LastName,Department,Birthdate,Description\n"+
+ "Tom,Jones,Marketing,1940-06-07Z,"Self-described as ""the top"" branding guru on the West Coast\n"+
+ "Ian,Dury,R&D,,"World-renowned expert in fuzzy logic design. Influential in technology purchases."\n";
+
+ client.addBatch(jobId, "text/csv; charset=UTF-8", csvData,
+ function(response){
+ console.log('Added batch '+response.batchInfo.id+'. State: '+response.batchInfo.state+'\n');
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error adding batch', jqXHR.responseText);
+ });
+
+See BulkAPISampleFiles for sample CSV and XML data for different operations.
+
+Close the job
+-------------
+
+You must close the job to inform Salesforce that no more batches will be submitted for the job.
+
+ client.closeJob(jobId, function(response){
+ console.log('Job closed. State: '+response.jobInfo.state+'\n');
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error closing job', jqXHR.responseText);
+ });
+
+Check batch status
+------------------
+
+ client.getBatchDetails(jobId, batchId, function(response){
+ console.log('Batch state: '+response.batchInfo.state+'\n');
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error getting batch details', jqXHR.responseText);
+ });
+
+Get batch results
+-----------------
+
+Pass `true` as the `parseXML` parameter to get batch results for a query, false otherwise.
+
+ client.getBatchResult(jobId, batchId, false, function(response){
+ console.log('Batch result: '+response);
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error getting batch result', jqXHR.responseText);
+ });
+
+Bulk query
+----------
+
+When adding a batch to a bulk query job, the `contentType` for the request must be either `text/csv` or `application/xml`, depending on the content type specified when the job was created. The actual SOQL statement supplied for the batch will be in plain text format.
+
+ var soql = 'SELECT Id, FirstName, LastName, Email FROM Contact';
+
+ client.addBatch(jobId, 'text/csv', soql, function(response){
+ console.log('Batch state: '+response.batchInfo.state+'\n');
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error getting batch result', jqXHR.responseText);
+ });
+
+Getting bulk query results is a two step process. Call `getBatchResult()` with `parseXML` set to `true` to get a set of result IDs, then call `getBulkQueryResult()` to get the actual records for each result
+
+ client.getBatchResult(jobId, batchId, true, function(response){
+ response['result-list'].result.forEach(function(resultId){
+ client.getBulkQueryResult(jobId, batchId, resultId, function(response){
+ console.log('Batch result: '+response);
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error getting bulk query results', jqXHR.responseText);
+ });
+ });
+ }, function(jqXHR, textStatus, errorThrown) {
+ console.log('Error getting batch result', jqXHR.responseText);
+ });
diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 0000000..522fa4a
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1,2 @@
+# Comment line immediately above ownership line is reserved for related gus information. Please be careful while editing.
+#ECCN:Open Source
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000..b4612a7
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,105 @@
+# Salesforce Open Source Community Code of Conduct
+
+## About the Code of Conduct
+
+Equality is a core value at Salesforce. We believe a diverse and inclusive
+community fosters innovation and creativity, and are committed to building a
+culture where everyone feels included.
+
+Salesforce open-source projects are committed to providing a friendly, safe, and
+welcoming environment for all, regardless of gender identity and expression,
+sexual orientation, disability, physical appearance, body size, ethnicity, nationality,
+race, age, religion, level of experience, education, socioeconomic status, or
+other similar personal characteristics.
+
+The goal of this code of conduct is to specify a baseline standard of behavior so
+that people with different social values and communication styles can work
+together effectively, productively, and respectfully in our open source community.
+It also establishes a mechanism for reporting issues and resolving conflicts.
+
+All questions and reports of abusive, harassing, or otherwise unacceptable behavior
+in a Salesforce open-source project may be reported by contacting the Salesforce
+Open Source Conduct Committee at ossconduct@salesforce.com.
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as
+contributors and maintainers pledge to making participation in our project and
+our community a harassment-free experience for everyone, regardless of gender
+identity and expression, sexual orientation, disability, physical appearance,
+body size, ethnicity, nationality, race, age, religion, level of experience, education,
+socioeconomic status, or other similar personal characteristics.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment
+include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy toward other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or
+advances
+* Personal attacks, insulting/derogatory comments, or trolling
+* Public or private harassment
+* Publishing, or threatening to publish, others' private information—such as
+a physical or electronic address—without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a
+professional setting
+* Advocating for or encouraging any of the above behaviors
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable
+behavior and are expected to take appropriate and fair corrective action in
+response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or
+reject comments, commits, code, wiki edits, issues, and other contributions
+that are not aligned with this Code of Conduct, or to ban temporarily or
+permanently any contributor for other behaviors that they deem inappropriate,
+threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces
+when an individual is representing the project or its community. Examples of
+representing a project or community include using an official project email
+address, posting via an official social media account, or acting as an appointed
+representative at an online or offline event. Representation of a project may be
+further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be
+reported by contacting the Salesforce Open Source Conduct Committee
+at ossconduct@salesforce.com. All complaints will be reviewed and investigated
+and will result in a response that is deemed necessary and appropriate to the
+circumstances. The committee is obligated to maintain confidentiality with
+regard to the reporter of an incident. Further details of specific enforcement
+policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good
+faith may face temporary or permanent repercussions as determined by other
+members of the project's leadership and the Salesforce Open Source Conduct
+Committee.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][contributor-covenant-home],
+version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html.
+It includes adaptions and additions from [Go Community Code of Conduct][golang-coc],
+[CNCF Code of Conduct][cncf-coc], and [Microsoft Open Source Code of Conduct][microsoft-coc].
+
+This Code of Conduct is licensed under the [Creative Commons Attribution 3.0 License][cc-by-3-us].
+
+[contributor-covenant-home]: https://www.contributor-covenant.org (https://www.contributor-covenant.org/)
+[golang-coc]: https://golang.org/conduct
+[cncf-coc]: https://github.com/cncf/foundation/blob/master/code-of-conduct.md
+[microsoft-coc]: https://opensource.microsoft.com/codeofconduct/
+[cc-by-3-us]: https://creativecommons.org/licenses/by/3.0/us/
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..9ba9791
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,14 @@
+BSD 3-Clause License
+
+Copyright (c) 2022 Salesforce, Inc.
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+3. Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/README.markdown b/README.markdown
index c29671c..b72c733 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,3 +1,7 @@
+> [!WARNING]
+> This project is deprecated, use [JSforce](https://jsforce.github.io/) instead.
+
+
Force.com JavaScript REST Toolkit
=================================
@@ -151,39 +155,50 @@ Your HTML page will need to include jQuery and the toolkit, then create a client
More fully featured samples are provided in [example.html](Force.com-JavaScript-REST-Toolkit/blob/master/example.html) and [mobile.html](Force.com-JavaScript-REST-Toolkit/blob/master/mobile.html).
-Using the Toolkit in a PhoneGap app
------------------------------------
+Using the Toolkit in a Cordova app
+----------------------------------
-Your HTML page will need to include jQuery, the toolkit, PhoneGap and the ChildBrowser plugin, then create a client object, passing a session ID to the constructor. You can use __https://login.salesforce.com/services/oauth2/success__ as the redirect URI and catch the page load in ChildBrowser.
+Your HTML page will need to include jQuery, the toolkit and Cordova. You will also need to install the [InAppBrowser](http://plugins.cordova.io/#/package/org.apache.cordova.inappbrowser) plugin to be able to pop up a browser window for authentication. Create a client object, passing a session ID to the constructor. You can use __https://login.salesforce.com/services/oauth2/success__ as the redirect URI and catch the page load in InAppBrowser.
An absolutely minimal sample using OAuth to obtain a session ID is:
+
-
-
-
-
-
+
+
+
-
Click here.
+
+
+
+
+
-A fully featured sample (including persistence of the OAuth refresh token to the iOS Keychain) is provided in [phonegap.html](Force.com-JavaScript-REST-Toolkit/blob/master/phonegap.html).
+A fully featured sample (including persistence of the OAuth refresh token to the iOS Keychain) for iOS is provided in [cordova-ios.html](https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/cordova-ios.html). The sample uses Cordova 4.3.0 and the InAppBrowser and iOS Keychain plugins. Install these with
+ cordova plugin add org.apache.cordova.inappbrowser
+ cordova plugin add com.shazron.cordova.plugin.keychainutil
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..e31774d
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,7 @@
+## Security
+
+Please report any security issue to [security@salesforce.com](mailto:security@salesforce.com)
+as soon as it is discovered. This library limits its runtime dependencies in
+order to reduce the total cost of ownership as much as can be, but all consumers
+should remain vigilant and have their security stakeholders review all third-party
+products (3PP) like this one and their dependencies.
\ No newline at end of file
diff --git a/bulk.page b/bulk.page
new file mode 100644
index 0000000..e9e7504
--- /dev/null
+++ b/bulk.page
@@ -0,0 +1,255 @@
+
+
+
+
+
+
1. Create a Bulk API job
+
+
+
+
+
+ External ID Field:
+
+
+
+
2. Select one or more CSV files to upload
+
+
+
+
+
2. Enter a SOQL Query
+
+
+
+
+
+
3. Close the Bulk API job
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/bulktk.js b/bulktk.js
new file mode 100644
index 0000000..4540aea
--- /dev/null
+++ b/bulktk.js
@@ -0,0 +1,241 @@
+/*
+ * Copyright (c) 2015, salesforce.com, inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the
+ * following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
+ * the following disclaimer in the documentation and/or other materials provided with the distribution.
+ *
+ * Neither the name of salesforce.com, inc. nor the names of its contributors may be used to endorse or
+ * promote products derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
+ * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * BulkTK: JavaScript library to wrap Force.com Bulk API. Extends ForceTK.
+ * Dependencies:
+ * jquery - http://jquery.com/
+ * ForceTK - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/forcetk.js
+ * jxon - https://github.com/developerforce/Force.com-JavaScript-REST-Toolkit/blob/master/jxon.js
+ * (originally from the [Ratatosk](https://github.com/wireload/Ratatosk)
+ * project; this version preserves case in element and attribute names)
+ */
+
+forcetk.Client.prototype.xmlHeader = "\n";
+
+/*
+ * Low level utility function to call the Bulk API.
+ * @param path resource path
+ * @param parseXML set to true to parse XML response
+ * @param callback function to which response will be passed
+ * @param [error=null] function to which jqXHR will be passed in case of error
+ * @param [method="GET"] HTTP method for call
+ * @param [contentType=null] Content type of payload - e.g. 'application/xml; charset=UTF-8'
+ * @param [payload=null] payload for POST
+ * @param [parseXML=false] set to true to parse XML response
+ */
+forcetk.Client.prototype.bulkAjax = function(path, parseXML, callback, error, method, contentType, payload, retry) {
+ var that = this;
+ var url = this.instanceUrl + path;
+
+ if (this.debug) {
+ console.log('bulkAjax sending: ', payload);
+ }
+
+ return $.ajax({
+ type: method || "GET",
+ async: this.asyncAjax,
+ url: (this.proxyUrl !== null) ? this.proxyUrl: url,
+ contentType: method == "DELETE" ? null : contentType,
+ cache: false,
+ processData: false,
+ data: payload,
+ success: function(data, textStatus, jqXHR) {
+ var respContentType = jqXHR.getResponseHeader('Content-Type');
+ // Naughty Bulk API doesn't always set Content-Type!
+ if (parseXML &&
+ ((respContentType && respContentType.indexOf('application/xml') === 0) ||
+ data.indexOf('
+
+
+
+
+ Accounts
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Login
+
+
+ Connecting to Force.com
+
+
+
Force.com
+
+
+
+
+
Account List
+
+
+
+
+
+
+
+
+
Force.com
+
+
+
+
+
Account Detail
+
+
+
+
Account Name:
+
Industry:
+
Ticker Symbol:
+
+
+
+
+
Force.com
+
+
+
+
+
New Account
+
+
+
+
+
+
Force.com
+
+
+
+
diff --git a/forcetk.js b/forcetk.js
index d965d2a..7fd2918 100644
--- a/forcetk.js
+++ b/forcetk.js
@@ -32,6 +32,9 @@
* console, go to Your Name | Setup | Security Controls | Remote Site Settings
*/
+/*jslint browser: true*/
+/*global alert, Blob, $, jQuery*/
+
var forcetk = window.forcetk;
if (forcetk === undefined) {
@@ -50,10 +53,11 @@ if (forcetk.Client === undefined) {
* PhoneGap etc
* @constructor
*/
- forcetk.Client = function(clientId, loginUrl, proxyUrl) {
+ forcetk.Client = function (clientId, loginUrl, proxyUrl) {
+ 'use strict';
this.clientId = clientId;
this.loginUrl = loginUrl || 'https://login.salesforce.com/';
- if (typeof proxyUrl === 'undefined' || proxyUrl === null) {
+ if (proxyUrl === undefined || proxyUrl === null) {
if (location.protocol === 'file:' || location.protocol === 'ms-appx:') {
// In PhoneGap
this.proxyUrl = null;
@@ -74,40 +78,42 @@ if (forcetk.Client === undefined) {
this.visualforce = false;
this.instanceUrl = null;
this.asyncAjax = true;
- }
+ };
/**
* Set a refresh token in the client.
* @param refreshToken an OAuth refresh token
*/
- forcetk.Client.prototype.setRefreshToken = function(refreshToken) {
+ forcetk.Client.prototype.setRefreshToken = function (refreshToken) {
+ 'use strict';
this.refreshToken = refreshToken;
- }
+ };
/**
* Refresh the access token.
* @param callback function to call on success
* @param error function to call on failure
*/
- forcetk.Client.prototype.refreshAccessToken = function(callback, error) {
- var that = this;
- var url = this.loginUrl + '/services/oauth2/token';
+ forcetk.Client.prototype.refreshAccessToken = function (callback, error) {
+ 'use strict';
+ var that = this,
+ url = this.loginUrl + '/services/oauth2/token';
return $.ajax({
type: 'POST',
- url: (this.proxyUrl !== null && ! this.visualforce) ? this.proxyUrl: url,
+ url: (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url,
cache: false,
processData: false,
data: 'grant_type=refresh_token&client_id=' + this.clientId + '&refresh_token=' + this.refreshToken,
success: callback,
error: error,
dataType: "json",
- beforeSend: function(xhr) {
- if (that.proxyUrl !== null && ! this.visualforce) {
+ beforeSend: function (xhr) {
+ if (that.proxyUrl !== null && !this.visualforce) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
}
}
});
- }
+ };
/**
* Set a session token and the associated metadata in the client.
@@ -117,32 +123,32 @@ if (forcetk.Client === undefined) {
* @param [instanceUrl] Omit this if running on Visualforce; otherwise
* use the value from the OAuth token.
*/
- forcetk.Client.prototype.setSessionToken = function(sessionId, apiVersion, instanceUrl) {
+ forcetk.Client.prototype.setSessionToken = function (sessionId, apiVersion, instanceUrl) {
+ 'use strict';
this.sessionId = sessionId;
- this.apiVersion = (typeof apiVersion === 'undefined' || apiVersion === null)
- ? 'v29.0': apiVersion;
- if (typeof instanceUrl === 'undefined' || instanceUrl == null) {
+ this.apiVersion = (apiVersion === undefined || apiVersion === null)
+ ? 'v29.0' : apiVersion;
+ if (instanceUrl === undefined || instanceUrl === null) {
this.visualforce = true;
// location.hostname can be of the form 'abc.na1.visual.force.com',
// 'na1.salesforce.com' or 'abc.my.salesforce.com' (custom domains).
// Split on '.', and take the [1] or [0] element as appropriate
- var elements = location.hostname.split(".");
-
- var instance = null;
- if(elements.length == 4 && elements[1] === 'my') {
+ var elements = location.hostname.split("."),
+ instance = null;
+ if (elements.length === 4 && elements[1] === 'my') {
instance = elements[0] + '.' + elements[1];
- } else if(elements.length == 3){
+ } else if (elements.length === 3) {
instance = elements[0];
} else {
instance = elements[1];
}
-
+
this.instanceUrl = "https://" + instance + ".salesforce.com";
} else {
this.instanceUrl = instanceUrl;
}
- }
+ };
/*
* Low level utility function to call the Salesforce endpoint.
@@ -152,41 +158,42 @@ if (forcetk.Client === undefined) {
* @param [method="GET"] HTTP method for call
* @param [payload=null] payload for POST/PATCH etc
*/
- forcetk.Client.prototype.ajax = function(path, callback, error, method, payload, retry) {
- var that = this;
- var url = (this.visualforce ? '' : this.instanceUrl) + '/services/data' + path;
+ forcetk.Client.prototype.ajax = function (path, callback, error, method, payload, retry) {
+ 'use strict';
+ var that = this,
+ url = (this.visualforce ? '' : this.instanceUrl) + '/services/data' + path;
return $.ajax({
type: method || "GET",
async: this.asyncAjax,
- url: (this.proxyUrl !== null && ! this.visualforce) ? this.proxyUrl: url,
- contentType: method == "DELETE" ? null : 'application/json',
+ url: (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url,
+ contentType: method === "DELETE" ? null : 'application/json',
cache: false,
processData: false,
data: payload,
success: callback,
- error: (!this.refreshToken || retry ) ? error : function(jqXHR, textStatus, errorThrown) {
+ error: (!this.refreshToken || retry) ? error : function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 401) {
- that.refreshAccessToken(function(oauthResponse) {
+ that.refreshAccessToken(function (oauthResponse) {
that.setSessionToken(oauthResponse.access_token, null,
- oauthResponse.instance_url);
+ oauthResponse.instance_url);
that.ajax(path, callback, error, method, payload, true);
},
- error);
+ error);
} else {
error(jqXHR, textStatus, errorThrown);
}
},
dataType: "json",
- beforeSend: function(xhr) {
- if (that.proxyUrl !== null && ! that.visualforce) {
+ beforeSend: function (xhr) {
+ if (that.proxyUrl !== null && !that.visualforce) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
}
xhr.setRequestHeader(that.authzHeader, "Bearer " + that.sessionId);
xhr.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
}
});
- }
+ };
/**
* Utility function to query the Chatter API and download a file
@@ -200,64 +207,61 @@ if (forcetk.Client === undefined) {
* @param [error=null] function to which request will be passed in case of error
* @param retry true if we've already tried refresh token flow once
*/
- forcetk.Client.prototype.getChatterFile = function(path, mimeType, callback, error, retry) {
- var that = this;
- var url = (this.visualforce ? '' : this.instanceUrl) + path;
+ forcetk.Client.prototype.getChatterFile = function (path, mimeType, callback, error, retry) {
+ 'use strict';
+ var that = this,
+ url = (this.visualforce ? '' : this.instanceUrl) + path,
+ request = new XMLHttpRequest();
- var request = new XMLHttpRequest();
-
- request.open("GET", (this.proxyUrl !== null && ! this.visualforce) ? this.proxyUrl: url, true);
+ request.open("GET", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, true);
request.responseType = "arraybuffer";
-
+
request.setRequestHeader(this.authzHeader, "Bearer " + this.sessionId);
request.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + this.apiVersion);
- if (this.proxyUrl !== null && ! this.visualforce) {
+ if (this.proxyUrl !== null && !this.visualforce) {
request.setRequestHeader('SalesforceProxy-Endpoint', url);
}
-
- request.onreadystatechange = function() {
+
+ request.onreadystatechange = function () {
// continue if the process is completed
- if (request.readyState == 4) {
+ if (request.readyState === 4) {
// continue only if HTTP status is "OK"
- if (request.status == 200) {
+ if (request.status === 200) {
try {
// retrieve the response
callback(request.response);
- }
- catch(e) {
+ } catch (e) {
// display error message
alert("Error reading the response: " + e.toString());
}
- }
- //refresh token in 401
- else if(request.status == 401 && !retry) {
- that.refreshAccessToken(function(oauthResponse) {
- that.setSessionToken(oauthResponse.access_token, null,oauthResponse.instance_url);
+ } else if (request.status === 401 && !retry) {
+ //refresh token in 401
+ that.refreshAccessToken(function (oauthResponse) {
+ that.setSessionToken(oauthResponse.access_token, null, oauthResponse.instance_url);
that.getChatterFile(path, mimeType, callback, error, true);
- },
- error);
- }
- else {
+ }, error);
+ } else {
// display status message
- error(request,request.statusText,request.response);
+ error(request, request.statusText, request.response);
}
- }
-
- }
+ }
+ };
request.send();
-
- }
-
+
+ };
+
// Local utility to create a random string for multipart boundary
- function randomString() {
- var str = '';
- for (var i = 0; i < 4; i++) {
- str += (Math.random().toString(16)+"000000000").substr(2,8);
+ var randomString = function () {
+ 'use strict';
+ var str = '',
+ i;
+ for (i = 0; i < 4; i += 1) {
+ str += (Math.random().toString(16) + "000000000").substr(2, 8);
}
return str;
- }
-
+ };
+
/* Low level function to create/update records with blob data
* @param path resource path relative to /services/data
* @param fields an object containing initial field names and values for
@@ -270,62 +274,63 @@ if (forcetk.Client === undefined) {
* @param [error=null] function to which response will be passed in case of error
* @param retry true if we've already tried refresh token flow once
*/
- forcetk.Client.prototype.blob = function(path, fields, filename, payloadField, payload, callback, error, retry) {
- var that = this;
- var url = (this.visualforce ? '' : this.instanceUrl) + '/services/data' + path;
- var boundary = randomString();
-
- var blob = new Blob([
- "--boundary_" + boundary + '\n'
- + "Content-Disposition: form-data; name=\"entity_content\";" + "\n"
- + "Content-Type: application/json" + "\n\n"
- + JSON.stringify(fields)
- + "\n\n"
- + "--boundary_" + boundary + "\n"
- + "Content-Type: application/octet-stream" + "\n"
- + "Content-Disposition: form-data; name=\"" + payloadField
- + "\"; filename=\"" + filename + "\"\n\n",
- payload,
- "\n\n"
- + "--boundary_" + boundary + "--"
- ], {type : 'multipart/form-data; boundary=\"boundary_' + boundary + '\"'});
-
- var request = new XMLHttpRequest();
- request.open("POST", (this.proxyUrl !== null && ! this.visualforce) ? this.proxyUrl: url, this.asyncAjax);
-
+ forcetk.Client.prototype.blob = function (path, fields, filename, payloadField, payload, callback, error, retry) {
+ 'use strict';
+ var that = this,
+ url = (this.visualforce ? '' : this.instanceUrl) + '/services/data' + path,
+ boundary = randomString(),
+ blob = new Blob([
+ "--boundary_" + boundary + '\n'
+ + "Content-Disposition: form-data; name=\"entity_content\";" + "\n"
+ + "Content-Type: application/json" + "\n\n"
+ + JSON.stringify(fields)
+ + "\n\n"
+ + "--boundary_" + boundary + "\n"
+ + "Content-Type: application/octet-stream" + "\n"
+ + "Content-Disposition: form-data; name=\"" + payloadField
+ + "\"; filename=\"" + filename + "\"\n\n",
+ payload,
+ "\n\n"
+ + "--boundary_" + boundary + "--"
+ ], {type : 'multipart/form-data; boundary=\"boundary_' + boundary + '\"'}),
+ request = new XMLHttpRequest();
+
+ request.open("POST", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, this.asyncAjax);
+
+ request.setRequestHeader('Accept', 'application/json');
request.setRequestHeader(this.authzHeader, "Bearer " + this.sessionId);
request.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + this.apiVersion);
- if (this.proxyUrl !== null && ! this.visualforce) {
+ request.setRequestHeader('Content-Type', 'multipart/form-data; boundary=\"boundary_' + boundary + '\"');
+ if (this.proxyUrl !== null && !this.visualforce) {
request.setRequestHeader('SalesforceProxy-Endpoint', url);
}
-
+
if (this.asyncAjax) {
- request.onreadystatechange = function() {
+ request.onreadystatechange = function () {
// continue if the process is completed
- if (request.readyState == 4) {
+ if (request.readyState === 4) {
// continue only if HTTP status is good
if (request.status >= 200 && request.status < 300) {
// retrieve the response
callback(request.response ? JSON.parse(request.response) : null);
- } else if(request.status == 401 && !retry) {
- that.refreshAccessToken(function(oauthResponse) {
- that.setSessionToken(oauthResponse.access_token, null,oauthResponse.instance_url);
- that.blob(path, fields, fileName, file, callback, error, true);
- },
- error);
+ } else if (request.status === 401 && !retry) {
+ that.refreshAccessToken(function (oauthResponse) {
+ that.setSessionToken(oauthResponse.access_token, null, oauthResponse.instance_url);
+ that.blob(path, fields, filename, payloadField, payload, callback, error, true);
+ }, error);
} else {
// return status message
error(request, request.statusText, request.response);
}
- }
- }
+ }
+ };
}
-
+
request.send(blob);
-
- return this.asyncAjax ? JSON.parse(request.response) : null;
- }
-
+
+ return this.asyncAjax ? null : JSON.parse(request.response);
+ };
+
/*
* Create a record with blob data
* @param objtype object type; e.g. "ContentVersion"
@@ -339,12 +344,13 @@ if (forcetk.Client === undefined) {
* @param [error=null] function to which response will be passed in case of error
* @param retry true if we've already tried refresh token flow once
*/
- forcetk.Client.prototype.createBlob = function(objtype, fields, filename,
- payloadField, payload, callback,
- error, retry) {
- return this.blob('/' + this.apiVersion + '/sobjects/' + objtype + '/',
- fields, filename, payloadField, payload, callback, error);
- }
+ forcetk.Client.prototype.createBlob = function (objtype, fields, filename,
+ payloadField, payload, callback,
+ error, retry) {
+ 'use strict';
+ return this.blob('/' + this.apiVersion + '/sobjects/' + objtype + '/',
+ fields, filename, payloadField, payload, callback, error, retry);
+ };
/*
* Update a record with blob data
@@ -360,12 +366,13 @@ if (forcetk.Client === undefined) {
* @param [error=null] function to which response will be passed in case of error
* @param retry true if we've already tried refresh token flow once
*/
- forcetk.Client.prototype.updateBlob = function(objtype, id, fields, filename,
- payloadField, payload, callback,
- error, retry) {
- return this.blob('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id +
- '?_HttpMethod=PATCH', fields, filename, payloadField, payload, callback, error);
- }
+ forcetk.Client.prototype.updateBlob = function (objtype, id, fields, filename,
+ payloadField, payload, callback,
+ error, retry) {
+ 'use strict';
+ return this.blob('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id +
+ '?_HttpMethod=PATCH', fields, filename, payloadField, payload, callback, error, retry);
+ };
/*
* Low level utility function to call the Salesforce endpoint specific for Apex REST API.
@@ -373,37 +380,56 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
* @param [method="GET"] HTTP method for call
- * @param [payload=null] payload for POST/PATCH etc
+ * @param [payload=null] string or object with payload for POST/PATCH etc or params for GET
* @param [paramMap={}] parameters to send as header values for POST/PATCH etc
* @param [retry] specifies whether to retry on error
*/
- forcetk.Client.prototype.apexrest = function(path, callback, error, method, payload, paramMap, retry) {
- var that = this;
- var url = this.instanceUrl + '/services/apexrest' + path;
+ forcetk.Client.prototype.apexrest = function (path, callback, error, method, payload, paramMap, retry) {
+ 'use strict';
+ var that = this,
+ url = this.instanceUrl + '/services/apexrest' + path;
+
+ method = method || "GET";
+
+ if (method === "GET") {
+ // Handle proxied query params correctly
+ if (this.proxyUrl && payload) {
+ if (typeof payload !== 'string') {
+ payload = $.param(payload);
+ }
+ url += "?" + payload;
+ payload = null;
+ }
+ } else {
+ // Allow object payload for POST etc
+ if (payload && typeof payload !== 'string') {
+ payload = JSON.stringify(payload);
+ }
+ }
return $.ajax({
- type: method || "GET",
+ type: method,
async: this.asyncAjax,
- url: (this.proxyUrl !== null) ? this.proxyUrl: url,
+ url: this.proxyUrl || url,
contentType: 'application/json',
cache: false,
processData: false,
data: payload,
success: callback,
- error: (!this.refreshToken || retry ) ? error : function(jqXHR, textStatus, errorThrown) {
+ error: (!this.refreshToken || retry) ? error : function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status === 401) {
- that.refreshAccessToken(function(oauthResponse) {
+ that.refreshAccessToken(function (oauthResponse) {
that.setSessionToken(oauthResponse.access_token, null,
- oauthResponse.instance_url);
+ oauthResponse.instance_url);
that.apexrest(path, callback, error, method, payload, paramMap, true);
- },
- error);
+ }, error);
} else {
error(jqXHR, textStatus, errorThrown);
}
},
dataType: "json",
- beforeSend: function(xhr) {
+ beforeSend: function (xhr) {
+ var paramName;
if (that.proxyUrl !== null) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', url);
}
@@ -412,13 +438,15 @@ if (forcetk.Client === undefined) {
paramMap = {};
}
for (paramName in paramMap) {
- xhr.setRequestHeader(paramName, paramMap[paramName]);
+ if (paramMap.hasOwnProperty(paramName)) {
+ xhr.setRequestHeader(paramName, paramMap[paramName]);
+ }
}
xhr.setRequestHeader(that.authzHeader, "Bearer " + that.sessionId);
xhr.setRequestHeader('X-User-Agent', 'salesforce-toolkit-rest-javascript/' + that.apiVersion);
}
});
- }
+ };
/*
* Lists summary information about each Salesforce.com version currently
@@ -427,9 +455,10 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.versions = function(callback, error) {
+ forcetk.Client.prototype.versions = function (callback, error) {
+ 'use strict';
return this.ajax('/', callback, error);
- }
+ };
/*
* Lists available resources for the client's API version, including
@@ -437,9 +466,10 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.resources = function(callback, error) {
+ forcetk.Client.prototype.resources = function (callback, error) {
+ 'use strict';
return this.ajax('/' + this.apiVersion + '/', callback, error);
- }
+ };
/*
* Lists the available objects and their metadata for your organization's
@@ -447,9 +477,10 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.describeGlobal = function(callback, error) {
+ forcetk.Client.prototype.describeGlobal = function (callback, error) {
+ 'use strict';
return this.ajax('/' + this.apiVersion + '/sobjects/', callback, error);
- }
+ };
/*
* Describes the individual metadata for the specified object.
@@ -457,10 +488,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.metadata = function(objtype, callback, error) {
- return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/'
- , callback, error);
- }
+ forcetk.Client.prototype.metadata = function (objtype, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/',
+ callback, error);
+ };
/*
* Completely describes the individual metadata at all levels for the
@@ -469,10 +501,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.describe = function(objtype, callback, error) {
+ forcetk.Client.prototype.describe = function (objtype, callback, error) {
+ 'use strict';
return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype
- + '/describe/', callback, error);
- }
+ + '/describe/', callback, error);
+ };
/*
* Creates a new record of the given type.
@@ -483,10 +516,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.create = function(objtype, fields, callback, error) {
- return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/'
- , callback, error, "POST", JSON.stringify(fields));
- }
+ forcetk.Client.prototype.create = function (objtype, fields, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/',
+ callback, error, "POST", JSON.stringify(fields));
+ };
/*
* Retrieves field values for a record of the given type.
@@ -497,16 +531,17 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.retrieve = function(objtype, id, fieldlist, callback, error) {
- if (arguments.length == 4) {
+ forcetk.Client.prototype.retrieve = function (objtype, id, fieldlist, callback, error) {
+ 'use strict';
+ if (arguments.length === 4) {
error = callback;
callback = fieldlist;
fieldlist = null;
}
var fields = fieldlist ? '?fields=' + fieldlist : '';
return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id
- + fields, callback, error);
- }
+ + fields, callback, error);
+ };
/*
* Upsert - creates or updates record of the given type, based on the
@@ -520,10 +555,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.upsert = function(objtype, externalIdField, externalId, fields, callback, error) {
- return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + externalIdField + '/' + externalId
- + '?_HttpMethod=PATCH', callback, error, "POST", JSON.stringify(fields));
- }
+ forcetk.Client.prototype.upsert = function (objtype, externalIdField, externalId, fields, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + externalIdField + '/' + externalId
+ + '?_HttpMethod=PATCH', callback, error, "POST", JSON.stringify(fields));
+ };
/*
* Updates field values on a record of the given type.
@@ -535,10 +571,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.update = function(objtype, id, fields, callback, error) {
- return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id
- + '?_HttpMethod=PATCH', callback, error, "POST", JSON.stringify(fields));
- }
+ forcetk.Client.prototype.update = function (objtype, id, fields, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id
+ + '?_HttpMethod=PATCH', callback, error, "POST", JSON.stringify(fields));
+ };
/*
* Deletes a record of the given type. Unfortunately, 'delete' is a
@@ -548,10 +585,11 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.del = function(objtype, id, callback, error) {
- return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id
- , callback, error, "DELETE");
- }
+ forcetk.Client.prototype.del = function (objtype, id, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/sobjects/' + objtype + '/' + id,
+ callback, error, "DELETE");
+ };
/*
* Executes the specified SOQL query.
@@ -560,11 +598,12 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.query = function(soql, callback, error) {
- return this.ajax('/' + this.apiVersion + '/query?q=' + escape(soql)
- , callback, error);
- }
-
+ forcetk.Client.prototype.query = function (soql, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/query?q=' + encodeURIComponent(soql),
+ callback, error);
+ };
+
/*
* Queries the next set of records based on pagination.
*
This should be used if performing a query that retrieves more than can be returned
@@ -575,19 +614,18 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.queryMore = function( url, callback, error ){
+ forcetk.Client.prototype.queryMore = function (url, callback, error) {
+ 'use strict';
//-- ajax call adds on services/data to the url call, so only send the url after
- var serviceData = "services/data";
- var index = url.indexOf( serviceData );
-
- if( index > -1 ){
- url = url.substr( index + serviceData.length );
- } else {
- //-- leave alone
+ var serviceData = "services/data",
+ index = url.indexOf(serviceData);
+
+ if (index > -1) {
+ url = url.substr(index + serviceData.length);
}
-
- return this.ajax( url, callback, error );
- }
+
+ return this.ajax(url, callback, error);
+ };
/*
* Executes the specified SOSL search.
@@ -596,8 +634,9 @@ if (forcetk.Client === undefined) {
* @param callback function to which response will be passed
* @param [error=null] function to which jqXHR will be passed in case of error
*/
- forcetk.Client.prototype.search = function(sosl, callback, error) {
- return this.ajax('/' + this.apiVersion + '/search?q=' + escape(sosl)
- , callback, error);
- }
+ forcetk.Client.prototype.search = function (sosl, callback, error) {
+ 'use strict';
+ return this.ajax('/' + this.apiVersion + '/search?q=' + encodeURIComponent(sosl),
+ callback, error);
+ };
}
diff --git a/jxon.js b/jxon.js
new file mode 100644
index 0000000..192694d
--- /dev/null
+++ b/jxon.js
@@ -0,0 +1,140 @@
+/*
+ * JXON.js
+ * Ratatosk
+ *
+ * Created by Alexander Ljungberg on March 15th, 2012.
+ *
+ * Public domain JXON implementation from algorithm #3 of:
+ * https://developer.mozilla.org/en/Parsing_and_serializing_XML
+ *
+ * Any copyright is dedicated to the Public Domain.
+ *
+ * Modified by Andrew (Pat) Patterson, 2015 from original at
+ * https://github.com/wireload/Ratatosk/blob/master/jxon.js
+ * to preserve case of element and attribute names
+ */
+
+JXON = function()
+{
+
+};
+
+JXON.buildValue = function(sValue)
+{
+ if (/^\s*$/.test(sValue))
+ return null;
+ if (/^(true|false)$/i.test(sValue))
+ return sValue.toLowerCase() === "true";
+ if (isFinite(sValue))
+ return parseFloat(sValue);
+ // Don't do this - it'll parse anything that looks like a date and get the timezone wrong.
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=693077
+ //if (isFinite(Date.parse(sValue)))
+ // return new Date(sValue);
+ return sValue;
+};
+
+JXON.fromXML = function(xmlString)
+{
+ return JXON.getJXONData((new DOMParser()).parseFromString(xmlString, "text/xml"));
+};
+
+JXON.getJXONData = function(oXMLParent)
+{
+ var vResult = /* put here the default value for empty nodes! */ null,
+ nLength = 0,
+ sCollectedTxt = "";
+ if (oXMLParent.hasAttributes && oXMLParent.hasAttributes())
+ {
+ vResult = {};
+ for (nLength; nLength < oXMLParent.attributes.length; nLength++)
+ {
+ oItAttr = oXMLParent.attributes.item(nLength);
+ vResult["@" + oItAttr.nodeName] = JXON.buildValue(oItAttr.value.replace(/^\s+|\s+$/g, ""));
+ }
+ }
+ if (oXMLParent.hasChildNodes())
+ {
+ for (var oItChild, sItKey, sItVal, nChildId = 0; nChildId < oXMLParent.childNodes.length; nChildId++)
+ {
+ oItChild = oXMLParent.childNodes.item(nChildId);
+ if (oItChild.nodeType === 4)
+ {
+ sCollectedTxt += oItChild.nodeValue;
+ } /* nodeType is "CDATASection" (4) */
+ else if (oItChild.nodeType === 3)
+ {
+ sCollectedTxt += oItChild.nodeValue.replace(/^\s+|\s+$/g, "");
+ } /* nodeType is "Text" (3) */
+ else if (oItChild.nodeType === 1 && !oItChild.prefix)
+ { /* nodeType is "Element" (1) */
+ if (nLength === 0)
+ vResult = {};
+ sItKey = oItChild.nodeName;
+ sItVal = JXON.getJXONData(oItChild);
+ if (vResult.hasOwnProperty(sItKey))
+ {
+ if (vResult[sItKey].constructor !== Array)
+ vResult[sItKey] = [vResult[sItKey]];
+ vResult[sItKey].push(sItVal);
+ }
+ else
+ {
+ vResult[sItKey] = sItVal;
+ nLength++;
+ }
+ }
+ }
+ }
+ if (sCollectedTxt)
+ nLength > 0 ? vResult.keyValue = JXON.buildValue(sCollectedTxt) : vResult = JXON.buildValue(sCollectedTxt);
+ /* if (nLength > 0) { Object.freeze(vResult); } */
+ return vResult;
+};
+
+JXON.loadObj = function(oParentObj, oParentEl, oNewDoc)
+{
+ var nSameIdx,
+ vValue,
+ oChild;
+ for (var sName in oParentObj)
+ {
+ vValue = oParentObj[sName];
+ if (sName === "keyValue")
+ {
+ if (vValue !== null && vValue !== true)
+ oParentEl.appendChild(oNewDoc.createTextNode(String(vValue)));
+ }
+ else if (sName.charAt(0) === "@")
+ oParentEl.setAttribute(sName.slice(1), vValue);
+ else
+ {
+ oChild = oNewDoc.createElement(sName);
+ if (vValue && vValue.constructor === Date)
+ oChild.appendChild(oNewDoc.createTextNode(vValue.toGMTString()));
+ else if (vValue && vValue.constructor === Array)
+ {
+ for (nSameIdx = 0; nSameIdx < vValue.length; nSameIdx++)
+ JXON.loadObj(vValue[nSameIdx], oChild);
+ }
+ else if (vValue && vValue instanceof Object)
+ {
+ JXON.loadObj(vValue, oChild, oNewDoc);
+ }
+ else if (vValue !== null && vValue !== true)
+ oChild.appendChild(oNewDoc.createTextNode(vValue.toString()));
+
+ oParentEl.appendChild(oChild);
+ // CPLog.error("Document: " + (new XMLSerializer()).serializeToString(oNewDoc));
+ }
+ }
+};
+
+JXON.toXML = function(oJXONObj, rootName)
+{
+ var oNewDoc = document.implementation.createDocument("", "", null),
+ rootNode = oNewDoc.createElement(rootName || 'xml');
+ oNewDoc.appendChild(rootNode);
+ JXON.loadObj(oJXONObj, rootNode, oNewDoc);
+ return (new XMLSerializer()).serializeToString(oNewDoc);
+};
diff --git a/mobileapp.js b/mobileapp.js
index f2e8de7..eeb9242 100644
--- a/mobileapp.js
+++ b/mobileapp.js
@@ -48,12 +48,12 @@ function addClickListeners() {
$('#deletebtn').click(function(e) {
// Delete the account
e.preventDefault();
- $.mobile.pageLoading();
+ $.mobile.loading('show');
client.del('Account', $('#accountdetail').find('#Id').val()
,
function(response) {
getAccounts(function() {
- $.mobile.pageLoading(true);
+ $.mobile.loading('hide');
$.mobile.changePage('#mainpage', "slide", true, true);
});
}, errorCallback);
@@ -62,7 +62,7 @@ function addClickListeners() {
$('#editbtn').click(function(e) {
// Get account fields and show the 'Edit Account' form
e.preventDefault();
- $.mobile.pageLoading();
+ $.mobile.loading('show');
client.retrieve("Account", $('#accountdetail').find('#Id').val()
, "Name,Id,Industry,TickerSymbol",
function(response) {
@@ -74,7 +74,7 @@ function addClickListeners() {
$('#actionbtn')
.unbind('click.btn')
.bind('click.btn', updateHandler);
- $.mobile.pageLoading(true);
+ $.mobile.loading('hide');
$.mobile.changePage('#editpage', "slide", false, true);
}, errorCallback);
});
@@ -94,7 +94,7 @@ function getAccounts(callback) {
.append('