{"id":11167,"library":"jsforce","title":"JSforce Salesforce API Library","description":"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.","status":"active","version":"3.10.14","language":"javascript","source_language":"en","source_url":"git://github.com/jsforce/jsforce","tags":["javascript","salesforce","salesforce.com","sfdc","force.com","database.com","typescript"],"install":[{"cmd":"npm install jsforce","lang":"bash","label":"npm"},{"cmd":"yarn add jsforce","lang":"bash","label":"yarn"},{"cmd":"pnpm add jsforce","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import { Connection } from 'jsforce';","symbol":"Connection","correct":"import jsforce from 'jsforce'; const conn = new jsforce.Connection({});"},{"note":"Similar to Connection, `OAuth2` is a property of the main `jsforce` export.","wrong":"import { OAuth2 } from 'jsforce';","symbol":"OAuth2","correct":"import jsforce from 'jsforce'; const oauth2 = new jsforce.OAuth2({});"},{"note":"Specific APIs like Tooling, Metadata, or Bulk are accessed as properties on an authenticated `jsforce.Connection` instance, not directly imported from the package.","wrong":"import { Tooling } from 'jsforce';","symbol":"Tooling","correct":"import jsforce from 'jsforce'; const tooling = conn.tooling;"}],"quickstart":{"code":"import jsforce from 'jsforce';\n\nasync function connectAndQuery() {\n  const conn = new jsforce.Connection({\n    // When using OAuth2, configure it here. For username/password flow, loginUrl is sufficient.\n    // oauth2: {\n    //   loginUrl: process.env.SF_LOGIN_URL ?? 'https://login.salesforce.com',\n    //   clientId: process.env.SF_CLIENT_ID ?? '',\n    //   clientSecret: process.env.SF_CLIENT_SECRET ?? '',\n    //   redirectUri: process.env.SF_REDIRECT_URI ?? '',\n    // }\n    loginUrl: process.env.SF_LOGIN_URL ?? 'https://login.salesforce.com'\n  });\n\n  try {\n    // Authenticate using username-password flow (convenient for scripts, but consider OAuth for broader applications)\n    await conn.login(\n      process.env.SF_USERNAME ?? '',\n      process.env.SF_PASSWORD_TOKEN ?? '' // password + security token (if enabled)\n    );\n    console.log('Successfully connected to Salesforce!');\n    console.log('Instance URL:', conn.instanceUrl);\n    console.log('User ID:', conn.userInfo?.id);\n\n    // Perform a SOQL query to fetch the first 5 Account records\n    const result = await conn.query<{ Id: string; Name: string }>('SELECT Id, Name FROM Account LIMIT 5');\n    console.log('Query Results (first 5 Accounts):');\n    result.records.forEach(record => {\n      console.log(`  ID: ${record.Id}, Name: ${record.Name}`);\n    });\n\n    // Example: Create a new Lead record\n    const createResult = await conn.sobject('Lead').create({\n      LastName: `JSforce Lead ${Date.now()}`,\n      Company: 'JSforce Corp',\n      Status: 'Open - Not Contacted'\n    });\n    console.log(`Created Lead with ID: ${createResult.id}, success: ${createResult.success}`);\n\n    // Example: Retrieve the newly created Lead record\n    if (createResult.success) {\n      const retrievedLead = await conn.sobject('Lead').retrieve(createResult.id);\n      console.log(`Retrieved Lead: ${retrievedLead.LastName} from ${retrievedLead.Company}`);\n    }\n\n  } catch (err: any) {\n    console.error('Error connecting or performing Salesforce operations:', err.message);\n  }\n}\n\nconnectAndQuery();","lang":"typescript","description":"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."},"warnings":[{"fix":"Refer to the official 'MIGRATING_V1-V3.md' guide in the jsforce GitHub repository for detailed steps and code changes required for migration.","message":"Major 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.","severity":"breaking","affected_versions":"<3.0"},{"fix":"Consult the 'MIGRATING_V2-V3.md' guide within the jsforce GitHub repository for specific changes and updates needed.","message":"Breaking 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.","severity":"breaking","affected_versions":"<3.0"},{"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.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0"},{"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');`.","message":"The 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'`).","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Incorrect Salesforce credentials (username, password, or security token) or the user's account is locked.","error":"INVALID_LOGIN: Invalid username, password, security token; or user locked out."},{"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.","cause":"Attempting to query or interact with an sObject (standard or custom object) that does not exist or is misspelled in the Salesforce organization.","error":"sObject type 'NonExistentObject__c' is not supported."},{"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.","cause":"An invalid SOQL query string was provided, often due to a misplaced comma, missing FROM clause, or incorrect field name.","error":"Syntax error. Extra ','"}],"ecosystem":"npm"}