{"id":13697076,"url":"https://github.com/ccoenraets/forcejs","last_synced_at":"2025-04-07T05:10:58.512Z","repository":{"id":19668852,"uuid":"22922346","full_name":"ccoenraets/forcejs","owner":"ccoenraets","description":"Micro library to use the Salesforce REST APIs in JavaScript Apps","archived":false,"fork":false,"pushed_at":"2018-01-12T20:12:03.000Z","size":252,"stargazers_count":176,"open_issues_count":17,"forks_count":61,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-03-30T22:10:02.032Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"arduino-libraries/RTCZero","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccoenraets.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-13T16:18:17.000Z","updated_at":"2025-02-12T17:46:04.000Z","dependencies_parsed_at":"2022-08-24T02:51:09.505Z","dependency_job_id":null,"html_url":"https://github.com/ccoenraets/forcejs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccoenraets%2Fforcejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccoenraets%2Fforcejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccoenraets%2Fforcejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccoenraets%2Fforcejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccoenraets","download_url":"https://codeload.github.com/ccoenraets/forcejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247595335,"owners_count":20963943,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T18:00:52.403Z","updated_at":"2025-04-07T05:10:58.492Z","avatar_url":"https://github.com/ccoenraets.png","language":"JavaScript","readme":"# ForceJS - JavaScript Toolkit for Salesforce APIs\n\nForceJS is a micro-library that makes it easy to use the Salesforce REST APIs in JavaScript applications. ForceJS allows you to easily authenticate with Salesforce using OAuth, and to manipulate Salesforce data using a simple API.\n\nThe main target of ForceJS are:\n- Client-side JavaScript applications deployed on your own server (Heroku or elsewhere)\n- Hybrid mobile apps built with Apache Cordova and the Salesforce Mobile SDK\n\nApplications deployed inside a Salesforce instance (Visualforce Page or Lightning Components) can use one of the data access utilities built into the Salesforce Platform instead: JavaScript Remoting, Remote Objects, Lightning Data Service, etc.   \n\n## Built on ECMAScript 6\n\nModern JavaScript applications now use ECMAScript 6 (aka ECMAScript 2015) and beyond. The current version of modern frameworks (such as React, Angular 2, and Ionic 2) are also built on top of ECMAScript 6 and beyond.\nTo support modern application development, and to integrate nicely with these frameworks, ForceJS is now built on top of ECMAScript 6 as well.  \n\n## Compatible with ECMAScript 5\n\nThe ECMAScript 6 source files are compiled into an ECMAScript 5 compatible version. The ECMAScript 5 compatible files are available in the `dist` directory. The ECMAScript 5 files support the Universal Module Definition (UMD) format. In other words, they can be used with AMD or CommonJS module loaders as well as globally using the `force.OAuth` and `force.DataService` variables.\n\n\u003e The original ECMAScript 5-only version of forcejs is still available in the [es5 branch](https://github.com/ccoenraets/forcejs/tree/es5) of this repository. The es5 branch is no longer actively developed.\n\n## Key Characteristics\n\n- No dependency\n- Loaded as an ECMAScript 6 module\n- Asynchronous calls return ECMAScript 6 promises   \n- Complete OAuth login workflow (User Agent)\n- Works transparently in the browser and in Cordova using the Salesforce Mobile SDK OAuth plugin\n- Automatically refreshes OAuth access_token (if available) on expiration\n- Tightly integrated with [force-server](https://github.com/ccoenraets/force-server), a local development server that works as a proxy and a local web server to provide a streamlined developer experience\n- Simple API to manipulate data (create, update, delete, upsert)\n- Supports connections to multiple instances of Salesforce in the same application\n- Works with modern JavaScript frameworks: React, Angular 2, Ionic 2, etc.\n\n## Modular\n\nForceJS is built on a modular architecture. It currently includes two modules:\n\n- **forcejs/oauth**: A module that makes it easy to authenticate with Salesforce using the OAuth User Agent workflow\n- **forcejs/data-service**: A module that makes it easy to access data through the Salesforce APIs\n\n`forcejs/oauth` and `forcejs/data-service` are typically used together in an application, but you can use them separately. For example, you could use **forcejs/oauth** by itself if all you need is a Salesforce access token (Lightning Out use cases). Similarly, you could use **forcejs/data-service** by itself if you already have an access token, and all you need is a simple library to access the Salesforce APIs.\n\n## Browser and Cordova Abstraction\n\nForceJS can be used to develop browser-based apps or hybrid mobile apps using the Salesforce Mobile SDK and Apache Cordova. If you develop a hybrid application using the Salesforce Mobile SDK, you often switch back and forth between running the app in the browser and on device. Developing in the browser is generally faster and easier to debug, but you still need to test device-specific features and check that everything runs as expected on the target platforms. The problem is that the configuration of OAuth and REST is different when running in the browser and on device. Here is a summary of the key differences:\n\n\u003ctable\u003e\n\u003ctr\u003e\u003ctd\u003e\u003c/td\u003e\u003ctd\u003e\u003cstrong\u003eBrowser\u003c/strong\u003e\u003c/td\u003e\u003ctd\u003e\u003cstrong\u003eMobile SDK\u003c/strong\u003e\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eRequires Proxy\u003c/td\u003e\u003ctd\u003eYes(*)\u003c/td\u003e\u003ctd\u003eNo\u003c/td\u003e\u003c/tr\u003e\n\u003ctr\u003e\u003ctd\u003eOAuth\u003c/td\u003e\u003ctd\u003eWindow Popup\u003c/td\u003e\u003ctd\u003eOAuth Plugin\u003c/td\u003e\u003c/tr\u003e\n\u003c/table\u003e\n\n(*) Starting in the Spring 15 release, some Salesforce REST APIs (like Chatter and sobjects) support CORS. To allow an app to make direct REST calls against your org, register the app domain in Setup: Administer \u003e Security Controls \u003e CORS.\n\nForceJS abstracts these differences and allows you to run your app in the browser and on device without code or configuration changes.\n\n## ECMAScript 6 Usage\n\n```javascript\nimport {OAuth, DataService} from 'forcejs';\n\nlet oauth = OAuth.createInstance();\noauth.login().then(oauthResult =\u003e DataService.createInstance(oauthResult));\n\nlet loadContacts = () =\u003e {\n    let service = DataService.getInstance();\n    service.query('select id, Name from contact LIMIT 50')\n        .then(response =\u003e {\n            let contacts = response.records;\n            // do something with contacts\n    });\n}\n```\n\nIf you are only using one of the forcejs submodules (either oauth or data), the following import syntax is recommended to make sure the compiled version does not include the module you don't use if your build tool doesn't support tree shaking:\n\n``` javascript\nimport OAuth from 'forcejs/oauth';\n//or\nimport DataService from 'forcejs/data-service';\n```\n\nBecause current browsers don't yet support all the ECMAScript 6 features, you need to use a build tool to compile (transpile) your ECMAScript 6 code to ECMAScript 5 compatible code, and provide the module loading infrastructure.\nWebpack, Browserify, and Rollup are popular options. Webpack instructions are provided in the Quick Start sections below. Frameworks like React, Angular 2, and Ionic 2 already come with a build process. If you are using these frameworks, no additional step is necessary.\n\n## ECMAScript 5 Usage\n\nUse the ECMAScript 5 compatible files available in the `dist` directory.\n\n```html\n\u003cscript src=\"force.all.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    var oauth = force.OAuth.createInstance();\n    oauth.login().then(function(oauthResult) {\n        force.DataService.createInstance(oauthResult);    \n    });\n\n    function loadContacts() {\n        var service = force.DataService.getInstance();\n        service.query('select id, Name from contact LIMIT 50')\n            .then(function(response) {\n                var contacts = response.records;\n                // do something with contacts\n            });\n    }\n\u003c/script\u003e\n```\n\nIf you are only using one of the forcejs modules (either oauth or data), the following  syntax is recommended to avoid including modules you don't use:\n\n```html\n\u003cscript src=\"force.oauth.js\"\u003e\u003c/script\u003e\n// or\n\u003cscript src=\"force.data-service.js\"\u003e\u003c/script\u003e\n\nvar oauth = force.OAuth.createInstance();\n// or\nvar service = force.DataService.createInstance(oauthResult);\n```\n\n## Quick Start 1: Simple Browser App\n\n1. Create a new directory for your project, navigate (`cd`) to that directory, and type the following command to initialize a project that uses the **npm** package manager (accept all the default values):\n\n    ```\n    npm init\n    ```\n\n1. Type the following command to install **forcejs**:\n\n    ```\n    npm install forcejs --save-dev\n    ```\n\n1. Type the following command to install the **force-server** development server:\n\n    ```\n    npm install force-server --save-dev\n    ```\n\n1. Type the following command to install **Webpack** and **Babel**:\n\n    ```\n    npm install babel-core babel-loader babel-preset-es2015 webpack --save-dev\n    ```\n\n1. Using your favorite editor, open `package.json` and modify the `scripts` section as follows:\n\n    ```\n    \"scripts\": {\n        \"webpack\": \"webpack\",\n        \"start\": \"force-server\"\n    },\n    ```\n\n1. In your project's root directory, create a file named `webpack.config.js`:\n\n    ```\n    var path = require('path');\n    var webpack = require('webpack');\n\n    module.exports = {\n        entry: './app.js',\n        output: {\n            filename: 'app.bundle.js'\n        },\n        module: {\n            loaders: [\n                {\n                    test: /\\.js$/,\n                    loader: 'babel-loader',\n                    query: {\n                        presets: ['es2015']\n                    }\n                }\n            ]\n        },\n        stats: {\n            colors: true\n        },\n        devtool: 'source-map'\n    };\n    ```\n\n1. In your project's root directory, create a file named `index.html`:\n\n    ```\n    \u003c!DOCTYPE html\u003e\n    \u003chtml\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eForcejs Quick Start\u003c/h1\u003e\n        \u003cul id=\"contacts\"\u003e\u003c/ul\u003e\n        \u003cscript src=\"app.bundle.js\"\u003e\u003c/script\u003e\n    \u003c/body\u003e\n    \u003c/html\u003e\n    ```\n\n1. In your project's root directory, create a file named `app.js`:\n\n    ```\n    import {OAuth, DataService} from 'forcejs';\n\n    let oauth = OAuth.createInstance();\n    oauth.login()\n        .then(oauthResult =\u003e {\n            DataService.createInstance(oauthResult);\n            loadContacts();\n        });\n\n    let loadContacts = () =\u003e {\n        let service = DataService.getInstance();\n        service.query('select id, Name from contact LIMIT 50')\n            .then(response =\u003e {\n                let contacts = response.records;\n                let html = '';\n                contacts.forEach(contact =\u003e html = html + `\u003cli\u003e${contact.Name}\u003c/li\u003e`);\n                document.getElementById(\"contacts\").innerHTML = html;\n        });\n    }\n    ```\n\n1. On the command line, type the following command to build your project:     \n\n    ```\n    npm run webpack\n    ```\n\n1. Type the following command to start the app in a browser:\n\n    ```\n    npm start\n    ```\n\n## Quick Start 2: Hybrid Mobile App with Cordova and the Mobile SDK\n\n1. Install Cordova and the Salesforce Mobile SDK for the platform of your choice. For example, for iOS:\n\n    ```\n    npm install -g cordova forceios\n    ```\n\n    On a Mac, you may have to use sudo:\n\n    ```\n    sudo npm install -g cordova forceios\n    ```\n\n1. Create a new mobile application:\n\n    ```\n    forceios create\n    ```\n\n1. Answer the prompts as follows (adjust the company id and organization name as needed):\n\n    ```\n    Enter your application type (native, hybrid_remote, or hybrid_local): hybrid_local\n    Enter your application name: myforcejsapp\n    Enter the output directory for your app (defaults to the current directory):\n    Enter your company identifier (com.mycompany): com.mycompany.myforcejsapp\n    Enter your organization name (Acme, Inc.): MyCompany, Inc.\n    Enter your Connected App ID (defaults to the sample app’s ID):\n    Enter your Connected App Callback URI (defaults to the sample app’s URI):\n    ```\n\n1. Navigate (cd) to the project directory:\n\n    ```\n    cd myforcejsapp\n    ```\n\n1. Type the following command to initialize a project that uses the `npm` package manager (accept all the default values):\n\n    ```\n    npm init\n    ```\n\n1. Type the following command to install **forcejs**:\n\n    ```\n    npm install forcejs --save-dev\n    ```\n\n1. Type the following command to install the **force-server** development server:\n\n    ```\n    npm install force-server --save-dev\n    ```\n\n1. Type the following command to install **Webpack** and **Babel**:\n\n    ```\n    npm install babel-core babel-loader babel-preset-es2015 webpack --save-dev\n    ```\n\n1. Using your favorite editor, open `package.json` and modify the `scripts` section as follows:\n\n    ```\n    \"scripts\": {\n        \"webpack\": \"webpack\",\n        \"start\": \"force-server --root www\"\n    },\n    ```\n\n1. In your project's root directory, create a file named `webpack.config.js`:\n\n    ```\n    var path = require('path');\n    var webpack = require('webpack');\n\n    module.exports = {\n        entry: './app/app.js',\n        output: {\n            path: path.resolve(__dirname, 'www'),\n            filename: 'app.bundle.js'\n        },\n        module: {\n            loaders: [\n                {\n                    test: /\\.js$/,\n                    loader: 'babel-loader',\n                    query: {\n                        presets: ['es2015']\n                    }\n                }\n            ]\n        },\n        stats: {\n            colors: true\n        },\n        devtool: 'source-map'\n    };\n    ```\n\n1. In your project's root directory, create a directory called `app`\n\n1. In the `app` directory, create a file named `app.js`:\n\n    ```\n    import {OAuth, DataService} from 'forcejs';\n\n    let oauth = OAuth.createInstance();\n    oauth.login()\n        .then(oauthResult =\u003e {\n            DataService.createInstance(oauthResult);\n            loadContacts();\n        });\n\n    let loadContacts = () =\u003e {\n        let service = DataService.getInstance();\n        service.query('select id, Name from contact LIMIT 50')\n            .then(response =\u003e {\n                let contacts = response.records;\n                let html = '';\n                contacts.forEach(contact =\u003e html = html + `\u003cli\u003e${contact.Name}\u003c/li\u003e`);\n                document.getElementById(\"contacts\").innerHTML = html;\n        });\n    }\n    ```\n\n1. In the `www` directory, delete all the files and directories except `bootconfig.json` and `index.html`\n\n1. Open `index.html`. Replace the content with:\n\n    ```\n    \u003c!DOCTYPE html\u003e\n    \u003chtml\u003e\n    \u003cbody\u003e\n        \u003ch1\u003eForcejs App\u003c/h1\u003e\n        \u003cul id=\"contacts\"\u003e\u003c/ul\u003e\n        \u003cscript src=\"cordova.js\"\u003e\u003c/script\u003e\n        \u003cscript src=\"app.bundle.js\"\u003e\u003c/script\u003e\n    \u003c/body\u003e\n    \u003c/html\u003e\n    ```  \n\n1. On the command line, type the following command to build your project:     \n\n  ```\n  npm run webpack\n  ```\n\n1. Type the following command to run the app in the browser:\n\n    ```\n    npm start\n    ```\n\n1. On a Mac, type the following command to build the app for iOS:\n\n    ```\n    cordova build ios\n    ```\n\n1. Run the app on your iOS device:\n    - Open `platforms/ios/myforcejsapp.xcodeproj` in Xcode\n    - Click `myforcejsapp` in the left sidebar\n    - In the `Signing` section, select a team corresponding to a valid certificate\n    - Click the Run button in the toolbar to run the application on your device.    \n\n## API Reference\n\n### forcejs/oauth\n\nBasic Usage:\n\n    import OAuth from \"forcejs/oauth\";\n    let oauth = OAuth.createInstance();\n    oauth.login().then(result =\u003e {\n        console.log(result); // Prints access token, instance URL, and refresh token (if any)\n    });\n\n#### createInstance(appId, loginURL, oauthCallbackURL)\n\n- **appId**\n\n    The Salesforce Connected App Id. For convenience, ForceJS uses a default connected app if the appId is not provided. The default connected app supports http://localhost:8200/oauthcallback.html as the OAuth callback URL to provide an out-of-the-box development experience using force-server. You need to create your own connected app with your own OAuth callback URL to run your application on a different server and port.\n\n    *Optional*\n\n    *Default:* 3MVG9fMtCkV6eLheIEZplMqWfnGlf3Y.BcWdOf1qytXo9zxgbsrUbS.ExHTgUPJeb3jZeT8NYhc.hMyznKU92\n\n- **loginURL**\n\n    The URL for the login window that should be used as part of the OAuth process.\n\n    *Optional*\n\n    *Default*: https://login.salesforce.com\n\n- **oauthCallbackURL**\n\n    The URL Salesforce calls back with an authenticated access token (or an error) at the end of the OAuth authentication workflow.\n\n    *Optional*\n\n    *Default*: The base URL the application was loaded from. For example, if you load the app from http://localhost:8200, the default OAuth callback URL is http://localhost:8200/oauthcallback.html. If you load the app from https://myserver.com/myapp, the default OAuth callback URL is https://myserver.com/myapp/oauthcallback.html\n\n#### login()\n\n  Starts the User Agent OAuth workflow using a popup window when running in the browser or the oauth plugin when running in Cordova.\n\n  - **Return Value**: A promise. When resolved, an object with the following fields is provided: **appId**, **accessToken**, **instanceURL**, **refreshToken**, and **userId**.\n\n## forcejs/data-service\n\nBasic Usage:\n\n    import Oauth from \"forcejs/oauth\";\n    import Service from \"forcejs/data-service\";\n    let oauth = OAuth.createInstance();\n    oauth.login().then(oauthResult =\u003e {\n        Service.createInstance(oauthResult);\n    });\n\n#### createInstance(oauth, options, name)\n\n- **oauth**. Required. An object with the following fields:\n\n    - **accessToken**\n\n        The authenticated access token\n\n        Required, no default\n\n    - **instanceURL**\n\n        The Salesforce instance URL\n\n        Required, no default\n\n    - **refreshToken**\n\n        The refresh token\n\n        Optional, no default\n\n- **options**. Optional. An object with the following fields:\n\n    - **useProxy**.\n\n        By default, ForceJS will automatically determine if it needs to use a CORS proxy: It won't use a proxy if the app is running inside a Visualforce page or a Cordova app, and will use the proxy in any other case. You can force ForceJS to always use a proxy by setting this value to true.\n\n        Starting in the Spring 15 release, some Salesforce REST APIs (like Chatter and sobjects) support CORS. To allow an app to make direct REST calls against your org, register the app domain in Setup: Administer \u003e Security Controls \u003e CORS. If you whitelist your domain and use APIs that support CORS, you can set useProxy to false.\n\n        Optional. Default: **false** if the app is running in Cordova or in a Visualforce page, **true** if it's not.\n\n    - **proxyURL**.\n\n        The URL of the CORS proxy server. This parameter is ignored when the app is running in Cordova or inside a Visualforce page.\n\n        Optional. Default: The base URL the application was loaded from. For example, if you load the app from http://localhost:8200, the default proxyURL is http://localhost:8200. If you load the app from https://myserver.com/myapp, the default proxyURL is https://myserver.com/myapp\n\n    - **apiVersion**\n\n        The version of the Salesforce API.\n\n        Optional. Default: v36.0\n\n- **name**\n\n    By default createInstance() creates a singleton instance which is what you want when your app works with a single Salesforce org. If you are building an app that connects to multiple Salesforce instances, provide a name that identifies the instance. For example:\n\n    ```\n    createInstance(oauth, options, \"sales\");\n    ```\n\n    You can later retrieve that specific instance using:\n\n    ```\n    getInstance(\"sales\");\n    ```\n\n    Optional. Default: none. If a name is not provided a singleton instance is created. If a name is provided, a named instance is provided.\n\n#### getInstance(name)\n\n- **name**\n\n    The name of the instance you want to retrieve.\n\n    Optional. If omitted, returns the singleton instance. If specified, return the named instance.\n\n#### getUserId()\n\n- **Return Value**: the id of the authenticated user.    \n\n\n#### query(soql)\n\nUsed to execute a SOQL statement\n\n- **soql**: The SOQL statement\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.query(\"SELECT id, name FROM contact\")\n    .then(result =\u003e {\n        console.log(result.records);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### create(objectName, valueObject)\n\nUsed to create a record for a Salesforce object\n\n- **objectName**. Required.\n- **valueObject**. Required.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n- **Return Value**: Promise. When the promise is resolved, an object with the following fields is provided:\n    - **errors**: an array of errors (if any)\n    - **id**: the record id of the record that was created\n    - **success**: true or false\n\nExample:\n\n```\nservice.create('contact', {FirstName: \"Lisa\", LastName: \"Jones\"})\n    .then(response =\u003e {\n        console.log(response);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### update(objectName, valueObject)\n\nUsed to update a record\n\n- **objectName**. Required.\n- **valueObject**. Required. The object must include and Id (or id) field to identify the record to update.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n-\n- **method**. Optional POST/PATCH\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.update('contact', {Id: \"0031a000001x7DOAAY\", FirstName: \"Emma\", LastName: \"Wong\"})\n    .then() =\u003e {\n        console.log(\"Update successful\");\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### del(objectName, recordId)\n\nUsed to delete a record\n\n- **objectName**. Required.\n- **recordId**. Required.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.del('contact', \"0031a000001x7DOAAY\",\n    .then() =\u003e {\n        console.log(\"Delete successful\");\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### upsert(objectName, externalIdField, externalId, data)\n\nUsed to upsert a record\n\nExample:\n\n```\nservice.upsert('contact', 'My_Contact_Id__c', '101', {FirstName: \"Emma\", LastName: \"Wong\"})\n    .then() =\u003e {\n        console.log(\"Upsert successful\");\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n\n\n#### retrieve(objectName, recordId, fields)\n\nUsed to retrieve a single record\n\n- **objectName**. Required.\n- **recordId**. Required.\n- **fields**. Optional. Array of fields to retrieve. If omitted, all available fields are retrieved.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.retrieve('contact', id)\n    .then(contact =\u003e {\n        console.log(contact);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### reports(recordId)\n\nUsed to return reports\n\n- **recordId**. optional if empty it return all created reports.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.reports()\n    .then(contact =\u003e {\n        console.log(reports);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### dasboard(recordId)\n\nUsed to return dashboards\n\n- **recordId**. optional if empty it return all created dashboards.\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n- **Return Value**: Promise\n\nExample:\n\n```\nservice.dashboard()\n    .then(contact =\u003e {\n        console.log(reports);\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### apexrest(urlMapping)\n\nUsed to invoke a custom REST service endpoint implemented by your own Apex class.\n\n- **urlMapping**. Required. Value of the urlMapping annotation in your Apex class.\n\n- **Return Value**: Promise\n\nExample:\n\n```\nforce.apexrest(\"contacts\")\n    .then(result =\u003e {\n        console.log(result)\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\n#### request(obj)\n\nThe core method to invoke a REST services. Other functions (query, create, update, del, upsert, apexrest) are just convenience functions invoking request() behind the scenes. You can use request() directly to invoke other REST services that are not directly exposed through a convenience function.\n\nExample:\n\n```\nforce.request({path: \"/services/data-service\"})\n    .then(result =\u003e {\n        console.log(result)\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\nParameters:\n\n- **path**\n\n    The path of the service to invoke\n\n- **method**\n\n    The HTTP method to execute: GET, POST, PUT, DELETE, PATCH\n\n    *Default*: GET\n\n- **contentType**\n\n    The request content type.\n\n- **params**\n\n    An object that will be turned into a query string appended to the request URL\n\n- **data**\n\n    An object representing data to be sent as the body of the request.\n\n#### chatter(obj)\n\nA convenience function to use the Chatter API\n\nExample:\n\n```\nforce.chatter({path: \"/users/me\"})\n    .then(result =\u003e {\n        console.log(result)\n    })\n    .catch(error =\u003e {\n        console.log(error);\n    });\n```\n\nParameters:\n\n- **path**\n\n    The path of the Chatter API service to invoke\n\n- **method**\n\n    The HTTP method to execute: GET, POST, PUT, DELETE, PATCH\n\n    *Default*: GET\n\n- **contentType**\n\n    The request content type.\n\n\n- **params**\n\n    An object that will be turned into a query string appended to the request URL\n\n- **data**\n\n    An object representing data to be sent as the body of the request.\n\n#### versions()\n\nLists summary information about each Salesforce.com version currently available, including the version, label, and a link to each version's root.\n\n#### resources()\n\nLists available resources for the client's API version, including resource name and URI.\n\n#### describeGlobal()\n\nLists the available objects and their metadata for your organization's data.\n\n#### metadata(objectName)\n\nDescribes the individual metadata for the specified object.\n\n- **objectName** Object name; e.g. \"Account\"\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n#### describe(objectName)\n\nCompletely describes the individual metadata at all levels for the specified object.\n\n- **objectName**: object name; e.g. \"Account\"\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n#### describeLayout(objectName, recordTypeId)\n\nFetches the layout configuration for a particular sobject name and record type id.\n\n- **objectName**: object name; e.g. \"Account\"\n- **recordTypeId** (optional): Id of the layout's associated record type\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n#### queryMore(url)\n\nQueries the next set of records based on pagination.\nThis should be used if performing a query that retrieves more than can be returned\nin accordance with http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_query.htm\n\n- **url**: the url retrieved from nextRecordsUrl or prevRecordsUrl\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n#### search(sosl)\n\nExecutes the specified SOSL search.\n\n- **sosl**: a string containing the search to execute - e.g. \"FIND {needle}\"\n- **batch** (optional): save query for batch call - see more under **.batch()**\n\n\n#### batch(requests)\n\nExecutes batch commands\nthe batch parameter in the other calls like query, create will save the request for the batch.\nSo you have to call before you execute this function.\nImportant note:\nIn API version 34.0 and later, subrequests can be calls to the Limits, SObject, Query/QueryAll, Search, Connect,\nand Chatter resources. API version 35.0 adds the ability to use Actions resources.\n\n\n- requests: Promises from the other calls like\n\n```\n// don't do it in production with nested promises :) Chain it or use observals\n    let query: string = 'SELECT id FROM Contact LIMIT 10';\n    let query1: string = 'SELECT id FROM Contact LIMIT 20';\n    let query2: string = 'SELECT id FROM Contact LIMIT 30';\n\n    DataService.getInstance().query(query, true).then(q1 =\u003e {\n      DataService.getInstance().query(query1, true).then(q2 =\u003e {\n        DataService.getInstance().query(query2, true).then(q3 =\u003e {\n          DataService.getInstance().batch([q1, q2, q3]).then((response) =\u003e {\n            console.log(q1, q2, q3);\n            console.log(response);\n          });\n        });\n      });\n    });\n```\n\n#### composite(request)\n- request: Promises from the other calls like","funding_links":[],"categories":["API"],"sub_categories":["Others","Picker"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccoenraets%2Fforcejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccoenraets%2Fforcejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccoenraets%2Fforcejs/lists"}