npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@salesforce/salesforce-sdk

v1.4.1

Published

Salesforce SDK for Node.js

Readme

Salesforce Function SDK for Node.js

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 Salesforce.com Program Agreement.

Usage

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:

const sdk = require('@salesforce/salesforce-sdk');

module.exports = async function (event, context, logger) {
     
     const soql = 'SELECT Name FROM Account';
     const queryResults = await context.org.data.query(soql);
     logger.info(JSON.stringify(queryResults));
     
     return queryResults;
}

and the same example in TypeScript is as follows:

import * as sdk from '@salesforce/salesforce-sdk';

export default async function execute(event: sdk.InvocationEvent, context: sdk.Context, logger: sdk.Logger): Promise<any> {

    const soql = 'SELECT Name FROM Account';
    const queryResults = await context.org.data.query(soql);
    logger.info(JSON.stringify(queryResults));

    return queryResults;
}

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 = async function (event, context, logger) {
    const payload = event.data;
    const uniqueId = Date.now();

    // Create a unit of work that inserts multiple objects.
    const work = context.org.unitOfWork;

    const account = new sdk.SObject('Account');
    account.setValue('Name', payload.accountName + uniqueId);
    work.registerNew(account);

    const contact = new sdk.SObject('Contact');
    contact.setValue('LastName', payload.contactName + uniqueId);
    contact.setValue('AccountId', account.fkId);
    work.registerNew(contact);

    const opportunity = new sdk.SObject('Opportunity');
    opportunity.setValue('Name', payload.opportunityName + uniqueId);
    opportunity.setValue('StageName', 'Prospecting');
    opportunity.setValue('CloseDate', Date.now());
    opportunity.setValue('AccountId', account.fkId);
    work.registerNew(opportunity);

    // Commit the unit of work.
    const response = await work.commit();
    if (response.success) {
        logger.info(JSON.stringify(response));
        const result = { 'accountId' : response.getResults(account)[0].id,
                         'contactId' : response.getResults(contact)[0].id,
                         'opportunityId' : response.getResults(opportunity)[0].id };
        logger.info('Committed a Unit of Work');
        logger.info(JSON.stringify(result));
    // If there was an error, log the root cause and throw an Error to indicate
    // a failed Function status
    } else {
        const errMsg = `Failed to commit Unit of Work. Root cause: ${response.rootCause}`;
        logger.error(errMsg);
        throw new Error(errMsg);
    }
}