Registry / crm-productivity / jsforce

jsforce

JSON →
library3.10.14jsnpmunverified

JSforce (formerly Node-Salesforce) is an isomorphic JavaScript library designed for interacting with the Salesforce API, capable of running in both web browsers and Node.js environments. The current stable version is 3.10.14, with releases primarily focusing on bug fixes and dependency updates within the 3.x series, indicating an active maintenance cadence. It provides comprehensive access to various Salesforce APIs including REST, Apex REST, Analytics, Bulk, Chatter, Metadata, SOAP, Streaming, and Tooling APIs. A key differentiator is its broad API coverage and isomorphic design, allowing developers to use a single library across different JavaScript runtimes. It also offers a command-line interface with a REPL for interactive exploration and learning. This library is a mature and widely used solution for integrating JavaScript applications with Salesforce.

npm install jsforce
INSTALL
IMPORT
SIG · JSFORCE
J
jsforce
crm-productivityjavascriptv3.10.14
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Connection
import jsforce from 'jsforce'; const conn = new jsforce.Connection({});
import { Connection } from 'jsforce';
The primary entry point, `jsforce.Connection`, is typically accessed via the default import (or `require`) of the library, as `jsforce` itself is the Connection class or an object containing it.
OAuth2
import jsforce from 'jsforce'; const oauth2 = new jsforce.OAuth2({});
import { OAuth2 } from 'jsforce';
Similar to Connection, `OAuth2` is a property of the main `jsforce` export.
Tooling
import jsforce from 'jsforce'; const tooling = conn.tooling;
import { Tooling } from 'jsforce';
Specific APIs like Tooling, Metadata, or Bulk are accessed as properties on an authenticated `jsforce.Connection` instance, not directly imported from the package.

This code snippet demonstrates how to establish a connection to Salesforce using jsforce, authenticate with username-password flow (suitable for scripts or backend services), perform a SOQL query to fetch account data, create a new Lead record, and then retrieve it. It highlights basic CRUD operations and error handling, showcasing the core interaction pattern with the Salesforce API.

import jsforce from 'jsforce'; async function connectAndQuery() { const conn = new jsforce.Connection({ // When using OAuth2, configure it here. For username/password flow, loginUrl is sufficient. // oauth2: { // loginUrl: process.env.SF_LOGIN_URL ?? 'https://login.salesforce.com', // clientId: process.env.SF_CLIENT_ID ?? '', // clientSecret: process.env.SF_CLIENT_SECRET ?? '', // redirectUri: process.env.SF_REDIRECT_URI ?? '', // } loginUrl: process.env.SF_LOGIN_URL ?? 'https://login.salesforce.com' }); try { // Authenticate using username-password flow (convenient for scripts, but consider OAuth for broader applications) await conn.login( process.env.SF_USERNAME ?? '', process.env.SF_PASSWORD_TOKEN ?? '' // password + security token (if enabled) ); console.log('Successfully connected to Salesforce!'); console.log('Instance URL:', conn.instanceUrl); console.log('User ID:', conn.userInfo?.id); // Perform a SOQL query to fetch the first 5 Account records const result = await conn.query<{ Id: string; Name: string }>('SELECT Id, Name FROM Account LIMIT 5'); console.log('Query Results (first 5 Accounts):'); result.records.forEach(record => { console.log(` ID: ${record.Id}, Name: ${record.Name}`); }); // Example: Create a new Lead record const createResult = await conn.sobject('Lead').create({ LastName: `JSforce Lead ${Date.now()}`, Company: 'JSforce Corp', Status: 'Open - Not Contacted' }); console.log(`Created Lead with ID: ${createResult.id}, success: ${createResult.success}`); // Example: Retrieve the newly created Lead record if (createResult.success) { const retrievedLead = await conn.sobject('Lead').retrieve(createResult.id); console.log(`Retrieved Lead: ${retrievedLead.LastName} from ${retrievedLead.Company}`); } } catch (err: any) { console.error('Error connecting or performing Salesforce operations:', err.message); } } connectAndQuery();
jsforce --version
Debug
Known issues
breakingMajor breaking changes exist between v1 and v3. Users migrating from older versions (especially v1) must consult the dedicated migration guide as API signatures and authentication mechanisms have significantly evolved.
fix
Refer to the official 'MIGRATING_V1-V3.md' guide in the jsforce GitHub repository for detailed steps and code changes required for migration.
affects: <3.0
breakingBreaking changes were also introduced between v2 and v3. While less extensive than v1 to v3, developers upgrading from v2 should review the migration notes to ensure compatibility.
fix
Consult the 'MIGRATING_V2-V3.md' guide within the jsforce GitHub repository for specific changes and updates needed.
affects: <3.0
deprecatedThe SOAP login() API (used by `loginBySoap` method) will be retired by Salesforce in Summer '27 (API version 65.0). Continued use after this date will result in authentication failures.
fix
Migrate authentication flows from `loginBySoap` to OAuth 2.0 Username-Password Flow or other OAuth 2.0 flows (e.g., Web Server Flow, JWT Bearer Flow) as appropriate for your application. Refer to Salesforce Release Notes for more information.
affects: >=1.0
gotchaThe default `jsforce` export is typically the `Connection` class or an object that contains it, leading to common mistakes in named imports (e.g., `import { Connection } from 'jsforce'`).
fix
Always use a default import for the main library: `import jsforce from 'jsforce';` then access `jsforce.Connection` or `new jsforce.Connection(...)`. For CommonJS, use `const jsforce = require('jsforce');`.
affects: >=1.0
Errors
Common errors & fixes
INVALID_LOGIN: Invalid username, password, security token; or user locked out.
Incorrect Salesforce credentials (username, password, or security token) or the user's account is locked.
fix
Verify username and password. Append your security token directly to the password if it's required and you haven't whitelisted your IP. Check Salesforce setup for IP ranges and user lockout status. Ensure the correct login URL (e.g., `https://test.salesforce.com` for sandboxes) is used.
sObject type 'NonExistentObject__c' is not supported.
Attempting to query or interact with an sObject (standard or custom object) that does not exist or is misspelled in the Salesforce organization.
fix
Double-check the API name of the sObject. For custom objects, ensure the `__c` suffix is correct. Verify that the user has permissions to access the object.
Syntax error. Extra ','
An invalid SOQL query string was provided, often due to a misplaced comma, missing FROM clause, or incorrect field name.
fix
Carefully review the SOQL query string for syntax errors. Validate field names and object names against your Salesforce schema. Test the query directly in the Salesforce Developer Console to isolate issues.
Upgrade
Version history
3.10.14latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
48 hits · last 30 days
node
42
OpenAI (training)
1
Resources