Salesforce javascript api

Salesforce javascript api DEFAULT

Migrating Components from Salesforce API 39 to API 40+

Coveo for Salesforce 4.0 (April 2020)

As of the release of Coveo for Salesforce V4, the following Lightning community components using Salesforce API 39 have been deleted in favour of newer, Lightning Locker compliant components.

All three of the newer components uses the SearchUI Lightning component to wrap the Coveo JavaScript Search Framework.

This nested component takes care of:

  • Loading your search page content

  • Initializing the Coveo JavaScript Search Framework

  • Providing customization options

This article provides guidelines to help you update these components without losing their current usability and customization.

Component Specifics

At first glance, the new component’s behavior is very similar to the component you’re already using. However, under the hood, it uses the SearchUI Lightning component to wrap the Coveo JavaScript Search Framework. Several component attributes have been removed or replaced in favor of utilizing the hooks provided by for passing data to the Coveo JavaScript Search Framework.

A few properties that were present on the designer view of the Coveo Search component have been removed. The following sections show how to migrate them.


The default value was , but users would usually set it to to execute some custom logic before performing the Coveo JavaScript Search Framework initialization. The same result can now be achieved through the hook. This hook allows you to specify a JavaScript Promise containing your custom logic. Once this promise resolves, the Coveo JavaScript Search Framework will perform its initialization process.


The default value was . If you set this property to , then you probably want to override the executed query in some cases. To do so, you should register an event handler on the event.

  1. Register the event handler on using .

  2. Implement your custom logic to override the query (see ).


The default value was . If you set this property to , then you want to override the initialization options. To do so, you should rely on the method.


This property isn’t available since the release of Salesforce API 44 (see Storable Actions).


This property was used to control the traces logged from the Coveo JavaScript Search Framework in the browser console.


With the new component you can specify a fixed logger level using a custom script.


This property was used to send custom context information on the search queries. You can achieve the same result by using the event.

  1. Add an event handler on as specified in .

  2. In the event handler, send the custom context information. In this example, we are sending a department name specified on the custom component. The contextual information can come from anywhere as long as your custom Lightning component has access to it.
  3. You can validate that the contextual information is passed to the Coveo Platform by inspecting the HTTP request performed by the search page.

    1. Open your web browser developer tools. Select the Network tab.

    2. Navigate to your community page.

    3. Locate the request that targets .

    4. In the request body, you will find the property with the custom information.

The default component appears to look and behave like it’s predecessor. However, as mentioned above, it uses a SearchUI Lightning component to wrap the Coveo JavaScript Search Framework. Furthermore, several component attributes have been removed or replaced in favor of the hooks provided by the for passing data to the Coveo JavaScript Search Framework.

Coveo Case Deflection

Following Salesforce’s Spring 18 release, the Lightning Create Case Form component was split into a component and a component.

Click here for more details.

Coveo’s API 40+ equivalent to the Coveo CaseCreation Lightning Component is a new Coveo Case Deflection component that replaces the aforementioned to work in conjunction with the .

The following property doesn’t exist in the . The following section explains how to migrate it.


The default value was . If you set this property to , then you probably want to override the executed query in some cases. To do so, you should register an event handler on the event.

  1. Register the event handler on using .

  2. Implement your custom logic to override the query (see ).

Passing Data to the Coveo JavaScript Search Framework

The updated components expose a certain number of options you can set via their attributes. For options that have to do with the Coveo JavaScript Search Framework, you can access the component’s attribute. The many hooks it provides allow you to run custom code at specific points in the initialization lifecycle as well as pass context and other options to the underlying Coveo JavaScript Search Framework.

Custom Scripts

If your customizations are for DOM manipulations, you can include custom scripts via static resource files in Salesforce as with the API 39 versions of the components.

See Adding JavaScript to the Coveo for Salesforce Lightning Components With Custom Code for more details on how to do so.

Custom Styling

As with the API 39 versions of the components, custom styling should be done directly in the wrapper component’s style sheet.


Access Salesforce data via APIs(JSForce) from Outside Service

At previous post,I had shared you how to setup an 《Awesome Node.js development environment with Heroku and Cloud9》.
Today I will continue to share about how to access Salesforce data via APIs from Outside Service.


JSforce (f.k.a. Node-Salesforce) is a isomorphic JavaScript Library utilizing Salesforce’s API: It works both in browser and with Node.js.

It capsulates the access to various APIs provided by Salesforce in asynchronous JavaScript function calls.
Reference: JSForce


Install JSForce library via npm from Cloud9 Console. c9 jsforce


Edit “app.js” with the following source code. Start node.js server and preview the application page,then we will see the infomations about API connect and UserInfo on console.
jsforce console

The most powerful thing of JSForce is that it supports almost all of the APIs,such as REST API,Metadata API and Tooling API.
Here we go.



Bulk API

Chatter API

Metadata API

Streaming API

Tooling API

Enjoy it!
Download JSForce from github

Post Tagged with Apex REST, Bulk API, Chatter API, JSforce, Metadata API, REST API, Streaming API, Tooling API

  1. Arlo k9
  2. Anime tongue
  3. Flowers quotes goodreads

Our Blog

Salesforce Integration with Node.js

Patterned roof

Photo by Dylan Wooters, 2020

Salesforce is huge. It is currently the dominant customer relationship management (CRM) provider, accounting for around 20% of market share. Businesses are using Salesforce not only as a traditional CRM solution, but also for novel purposes. Salesforce can serve as a backend database and admin portal for custom apps, or as a reporting tool that pulls data from various systems.

This growth leads to increasing demand for Salesforce integrations. The term “Salesforce integration” may conjure up images of expensive enterprise software or dense API documentation, but it doesn’t have to be that way. You can work with Salesforce easily using Node.js and the npm package JSforce. An example of a project that might benefit from this kind of Node.js integration is an e-commerce website where order data is loaded to and from Salesforce for order fulfillment, tracking, and reporting.

In this post we’ll cover how to connect to Salesforce using JSforce, the basics of reading and writing data, as well as some advanced topics like working with large amounts of data and streaming data with Socket.IO.

Setting Up

You’ll first want to install Node.js on your local machine, if you haven’t done so already.

Next, create your Node app. This will vary with your requirements. I often use Express to build a REST API for integration purposes. Other times, if I am routinely loading data into Salesforce, I will create Node scripts and schedule them using cron. For the purposes of this post, we will create a small Node script that can be run on the command line.

Create a new directory for your project, and within that directory, run to generate your package.json file. Then install JSforce with .

Finally, create a file named script.js, which we will run on the command line for testing. To test the script at any time, simply navigate to your app’s directory and run .

At the top of the script, require , as well as the Node IO libraries and . Then define an asynchronous function that will serve as our script body. This is where all of your Salesforce code will go.

Connecting to Salesforce

I usually store my Salesforce credentials and instance URL as a JSON object in a separate file, which I gitignore. This ensures that sensitive data does not appear in Git. Below is the content of my salesforce-creds.json file. You’ll want to add your Salesforce username and password and update the instance URL, if necessary.

To connect to Salesforce simply retrieve the credentials from the file and use them with the JSforce Connection class to login. Be sure to wrap all JSforce code in a try-catch block, to catch any errors coming back from Salesforce.

Reading, Writing, and Deleting Data

Once connected, the easiest way to query data from Salesforce is to use the JSforce query function, and pass in an SOQL statement. This offers the most flexibility, as you can run queries for child and parent objects. Using SOQL, we can query all accounts and their contacts (children) in a single statement. Note, however, that there are limitations on relationship queries. You can only go down one level, from parent to child, but you can go up multiple levels from child to parent.

Writing and deleting data is simple with JSforce using the class and the corresponding create/update/delete function. In the example below, we will query for accounts and contacts using SOQL, and then isolate and update a specific contact using .

Working with Large Amounts of Data

You may need to read and write large amounts of data, for example if you are using Salesforce for reporting and loading data to and from other systems.

Event-driven Querying

The record limit for standard promise-style SOQL querying, as in our example above, is 2000 records. To query more than that, it is best to shift to the event-driven style of querying. This will ensure that all records are successfully retrieved from Salesforce. You can use the property to set the upper limit of records returned. By default, is set to 10,000.

Loading Data with the Bulk API

Loading a large amount of data into Salesforce is best accomplished through the Bulk API via JSforce. There are a couple good reasons for this approach.

The Bulk API has better performance over other methods when working with large collections of objects.

The standard JSforce create/update/delete functions have a 200 object limit. For operations on large collections, you must divide the total by 200, resulting in many separate API calls. By contrast, the Bulk API only uses a single API call. Since Salesforce imposes API limits, this makes the Bulk API a better choice.

Running a bulk operation is simple using the method, which takes three parameters: the Salesforce object type, the operation type, and an array of objects. The method returns an array of objects with success/errors fields, as well as the id of the newly created object, if successful.

If you’re working with thousands of objects, it’s good to set the pollTimeout property manually to one minute or more, to avoid Salesforce connection timeouts. Also note that the possible values for operation type are: ‘insert’, ‘update’, ‘upsert’, ‘delete’, or ‘hardDelete’.

WebSocket Streaming with

Say you are building a web application for reporting, and the app contains a dashboard with data on all of your contacts in Salesforce. You want the dashboard to be updated whenever the data in Salesforce changes, and you also want this to happen without refreshing the web page.

To accomplish this, you can stream real-time data from Salesforce using JSforce and the Socket.IO library, which makes working with WebSockets quite simple.

The first step in this process is creating a PushTopic in Salesforce. This is basically a trigger that emits a notification anytime an object is created, updated, etc. in Salesforce. I created a PushTopic for Contacts by running the following Apex code in the Salesforce developer console.

Then, back in your Node app, install Express and Socket.IO.

Next, you’ll want to create a very basic Express server that will listen for updates from the Salesforce PushTopic, and emit them to your reporting site. Start by installing Express and Socket.IO.

Then delete the function in your script.js file, which contained the code from the samples above, and replace it with the following:

Here is a step-by-step description of what is occurring in the code sample above:

  • The Express server is set to listen for connections on port 3000.
  • We connect to Salesforce and login.
  • Socket.IO is set to listen for incoming connections from clients.
  • A function called that emits Salesforce streaming messages to the client is defined.
  • When a connection is made, is attached to the Salesforce streaming topic as a callback, using the live Salesforce connection.

If you follow the nice little tutorial from Socket.IO and create the sample chat webpage, you can actually test the Salesforce streaming updates. In the chat page, add this script, which will log messages coming back from Salesforce.

Then update a contact in Salesforce, changing the contact’s first name. If everything works correctly, you should see the client connect via Socket.IO in the Node logs, and also see a streaming message from Salesforce logged in the browser’s console window.


Node.js and JSforce provide a straightforward and elegant way to interact with Salesforce. Whether you have an existing Node API that needs to work with Salesforce, or you are building a new application that is powered by Salesforce data, consider the recipes above as stepping stones for completing your project.


Integrating a Node.js application with Salesforce

Lightning Web Components (LWC), Salesforce’s latest technology for building custom components, are quickly being adopted by many organizations. After all, they improve performance, provide an easy learning curve, and utilize widely accepted standards for development. LWCs allow for rapid development and deployment of custom features inside and out of Salesforce using Lightning Web Components Open Source.

One common requirement for building a web component like an LWC is integrating with a third-party API. In Salesforce, most often accomplish this via backend logic, using Apex to make the necessary callouts, certainly a viable solution. However, for best performance and to facilitate reuses outside of Salesforce, you should put much of the processing logic in the client and avoid unnecessary calls to the server. Over the next few paragraphs, I will outline one approach you can take to do this using JavaScript’s ES6 modules, Fetch API, and Promises.


The Cornell Lab of Ornithology maintains the world’s largest repository of bird sightings in the world. Anyone can submit data to it through its eBird portal. eBird provides the science community with invaluable conservation data and bird enthusiasts with a way to record their sightings. The amount of data amounts to hundreds of millions of sightings. Cornell generously exposes all of this data via an API. You can query to get sightings by location or by region. You can query to get a sighting of a specific species. The API also provides the ability to retrieve a list of species and locations. All of this can be harnessed into a highly reusable module using the JavaScript capabilities I previously mentioned.

Think Reuse!

To create an LWC that retrieves data from the client-side, the logic could be encapsulated within the component’s JavaScript file. However, this would likely be a poor decision. What if ten different LWC’s and an external system that implements React all needed to make callouts to this same API. Wouldn’t it be nice to have one reusable piece of logic that they could all utilize? Absolutely! Designing for reuse is an extremely important consideration in most coding efforts, especially when the level of effort is very low. Bring in JavaScript ES6 modules.

The concept of modular development is certainly not new, but it is a relatively new concept for JavaScript. Modules for JavaScript did not come along until the ES6 release in 2015. Modules provide a mechanism, the export keyword, for exposing logic that can be imported into JavaScript files.

In the case of building a module to integrate with the eBird API, this module will consist of a series of functions that make callouts to the API. The module abstracts away all of the integration specifics like authentication and endpoint variations. The user needs only to import the module then call the function that returns the required data.

For the eBird service module, each API callout has a corresponding function. For instance, you can reach the eBird Taxonomy endpoint using the getTaxonomy function. The functions handle generating the endpoint URL, executing the callout, and processing the response. Each returns the response body in the form of a Promise (more on these in a bit).

Go Fetch!

All of the eBird service callouts are executed using another feature added to JavaScript in the ES6 release, the Fetch API. Specifically, the fetch function of the Fetch API. This capability allows for skipping calls to the backend, enabling easy modularization of the eBird service. The fetch function takes one argument, the endpoint, and one optional argument, an object containing request options, then returns a response in the form of a Promise (still coming). The response is like any HTTP response, containing a header, response code, and a body. The code below shows how to call the fetch function. The then and catch blocks process the Promises that are returned by each call.

I Promise!

As promised, here is the Promise. A Promise is a promise of completion of an asynchronous operation and the return of its results. Promises start off as pending, then transition to fulfilled, if successful, or rejected, if not successful. The resolve function is called when the Promise is successful, and the reject function is called when the Promise is not successful.

Promises are handled using then and catch blocks. Then blocks handle fulfilled promises and catch blocks handle rejected promises.

As shown above, each block takes a callback as an argument. The callback contains the logic that processes the data returned by the Promise.

Bring It All Together

So how do all of these pieces fit together? Simple enough. The eBird Service is a separate JavaScript file with a series of functions that follow this pattern:

As can be seen, each function returns a promise based upon the results of the callout executed using the fetch function.

In the LWC, the function(s) must be imported before being called. This is done in the component’s JavaScript file using the import keyword.

Once imported, the function is ready to be used in the LWC.

In the end, we now have a reusable JavaScript service that will save time and money at each integration point. For LWCs, there is also the benefit of not having to add a layer of asynchronous functionality by calling backend logic to do the callouts. So, with LWCs, not only do you get both the time and cost savings, but you also get a performance boost.

Our team often works with Salesforce Lightning Components to deliver the performance our clients need on the platform. If you’re looking for something similar or want to do more with Salesforce, contact our team to learn how we can help.


Javascript api salesforce


Salesforce API Library for JavaScript applications (both on web browser and Node.js)



JSforce (f.k.a. Node-Salesforce) is an isomorphic JavaScript Library utilizing Salesforce's API: It works both in the browser and with Node.js.

It capsulates the access to various APIs provided by Salesforce in asynchronous JavaScript function calls.

It also has command line interface (CLI) which gives interactive console (REPL), so you can learn the usage without hassle.

Supported Salesforce APIs are the following:

  • REST API (SOQL, SOSL, describe, etc.)
  • Apex REST
  • Analytics API
  • Bulk API
  • Chatter API
  • Metadata API
  • Streaming API
  • Tooling API


See documentation in .


See Releases.


See license (MIT License).



If you have any questions first file it on issues before contacting authors via e-mail.


In order to run tests you will need a Salesforce Developer Org

You will also need to install the JsforceTestSuite package, which can be done by running:

You may need to run this more then once if you encounter timeouts or dropped connections/

Finally, to run the tests simply do:


Your contributions are welcome: both by reporting issues on GitHub issues or pull-requesting patches.

If you want to implement any additional features, to be added to JSforce to our master branch, which may or may not be merged please first check current opening issues with milestones and confirm whether the feature is on road map or not.

If your feature implementation is brand-new or fixing unsupposed bugs in the library's test cases, please include addtional test codes in the directory.

Call External API from Lightning Web Component - Fetch API in JavaScript


Note: This feature is in beta and has been released early so we can collect feedback. It may contain significant problems, undergo major changes, or be discontinued. The use of this feature is governed by the Program Agreement.


All function implementations must export a function accepting these arguments:

  • InvocationEvent containing the payload for the function, etc.
  • Context containing utility and Salesforce API classes to call back to the invoking org
  • Logger for logging diagnostic/status messages

Functions must return an object that can be serialized to JSON.

The following JavaScript example makes a SOQL query to a Salesforce org:

constsdk=require('@salesforce/salesforce-sdk');module.exports=asyncfunction(event,context,logger){constsoql='SELECT Name FROM Account';;;returnqueryResults;}

and the same example in TypeScript is as follows:

import * assdkfrom'@salesforce/salesforce-sdk';exportdefaultasyncfunctionexecute(event: sdk.InvocationEvent,context: sdk.Context,logger: sdk.Logger): Promise<any>{constsoql='SELECT Name FROM Account';;;returnqueryResults;}

For more complex transactions, the SDK provides the UnitOfWork class. A UnitOfWork represents a set of one or more Salesforce operations that need to be done as a single atomic operation. The following JavaScript example uses a UnitOfWork to create an Account record and several related records:

For the Salesforce Functions pilot, always use a new instance of UnitOfWork for each transaction and never re-use a committed UnitOfWork.

module.exports=asyncfunction(event,context,logger){;;// Create a unit of work that inserts multiple;constaccount=newsdk.SObject('Account');account.setValue('Name',payload.accountName+uniqueId);work.registerNew(account);constcontact=newsdk.SObject('Contact');contact.setValue('LastName',payload.contactName+uniqueId);contact.setValue('AccountId',account.fkId);work.registerNew(contact);constopportunity=newsdk.SObject('Opportunity');opportunity.setValue('Name',payload.opportunityName+uniqueId);opportunity.setValue('StageName','Prospecting');opportunity.setValue('CloseDate',;opportunity.setValue('AccountId',account.fkId);work.registerNew(opportunity);// Commit the unit of work.constresponse=awaitwork.commit();if(response.success){;constresult={'accountId' : response.getResults(account)[0].id,'contactId' : response.getResults(contact)[0].id,'opportunityId' : response.getResults(opportunity)[0].id};'Committed a Unit of Work');;// If there was an error, log the root cause and throw an Error to indicate// a failed Function status}else{consterrMsg=`Failed to commit Unit of Work. Root cause: ${response.rootCause}`;logger.error(errMsg);thrownewError(errMsg);}}

Now discussing:

Ksenia glanced at the clock in the corridor and realized that that was exactly how much she had left until the end of the working day. A crazy thought flashed through my head that Oksana knew exactly how long Ksyusha was working. Where did it come from.

3743 3744 3745 3746 3747