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 🙏

© 2024 – Pkg Stats / Ryan Hefner

salesforceliteconnection

v1.0.0

Published

it is a promise based library that wraps Salesforce CRUD rest api. it is meant to be used in apps that require a one time connection to Salesforce. SalesforceLiteConnection uses the Username-Password OAuth Authentication Flow as.

Downloads

1

Readme

SalesforceLiteConnection

it is a promise based library that wraps Salesforce CRUD rest api. it is meant to be used in apps that require a one time connection to Salesforce. SalesforceLiteConnection uses the Username-Password OAuth Authentication Flow as.

Requirements

  1. A connected app
  2. Salesforce user credentials

Caveats

  1. It does not provide a refresh token.
  2. SalesforceConnection instance can only be created through SalesforceLiteConnection.createConnection.

Installation

npm install salesforceLiteConnection

API

SalesforceLiteConnection

createConnection(authInfo)

Creates a connection to a salesforce org specify the params

Parameters

  • authInfo object specifies the information about where to connect

Return

Promise (it resolves into an instance of SalesforceConnection);

Example

const SalesforceLiteConnection = require('salesforceLiteConnection');

SalesforceLiteConnection.createConnection({
  clientId: 'CONNECTED_APP_ID',                         // Required
  clientSecret: 'CONNECTED_APP_SECRET',                 // Required
  username: 'SALESFORCE_USERNAME',                      // Required
  password: 'SALESFORCE_USERNAME_PASSWORD',             // Required
  secretToken: 'SALESFORCE_USERNAME_SECRET_TOKEN',      // Required
  apiVersion: 45                                        // Optional (Default 45)
  isProd: true|false,                                   // Optional (Default false)
})
.then(conn => {
  // perform CRUD operations using the SalesforceConnection instance
})
.catch(() => {
  // implement error handling
});

SalesforceConnection

query(soql)

Executes the given soql string.

Parameters

  • soql string soql query to execute

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_query.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.query('SELECT Id, Name FROM Account')
  })
  .then((data) => {
    console.log(data);
  });

insert(sobjectApiName, fieldsToSet)

Inserts a record.

Parameters

  • sobjectApiName string sobject api name
  • fieldsToSet object fields to set

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.insert('Account', {
      Name: 'Fake Corp'
    })
  })
  .then((data) => {
    console.log(data);
  });

update(sobjectApiName, recordId, fieldsToUpdate)

Updates a record.

Parameters

  • sobjectApiName string sobject api name
  • recordId string record to update
  • fieldsToSet object fields to update

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_update_fields.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.update('Account', '001xx000003DGb2AAG', {
      Name: 'Fake INC.'
    })
  })
  .then((data) => {
    console.log(data);
  });

delete(sobjectApiName, recordId)

Deletes a record.

Parameters

  • sobjectApiName string sobject api name
  • recordId string record to update

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_delete_record.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.delete('Account', '001xx000003DGb2AAG', {
      Name: 'Fake INC.'
    })
  })
  .then((data) => {
    console.log(data);
  });

bulkInsert(sobjectApiName, records, allOrNone)

Inserts a collection of records (up to 200 records).

Parameters

  • sobjectApiName string sobject api name
  • records array Collection of records to insert
  • allOrNone boolean Indicates whether to roll back the entire request when the creation of any object fails (default true)

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobjects_collections_create.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.bulkInsert('Contact', [{
      LastName : "Doe",
      FirstName : "Erica"
    }, {
      LastName : "Doe",
      FirstName : "Mike"
    }])
  })
  .then((data) => {
    console.log(data);
  });

bulkUpdate(sobjectApiName, records, allOrNone)

Updates a collection of records (up to 200 records).

Parameters

  • sobjectApiName string sobject api name
  • records array Collection of records to update (each record must have the Id field filled)
  • allOrNone boolean Indicates whether to roll back the entire request when the update of any object fails (default true)

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobjects_collections_update.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.bulkUpdate('Contact', [{
      Id: '001xx000003DGb2AAG',
      Title: 'Lead Engineer'
    }, {
      Id: '003xx000004TmiQAAS',
      Title: 'UI Designer'
    }])
  })
  .then((data) => {
    console.log(data);
  });

bulkDelete(sobjectApiName, recordIds, allOrNone)

Updates a collection of records (up to 200 records).

Parameters

  • sobjectApiName string sobject api name
  • recordIds array Collection of record to delete
  • allOrNone boolean Indicates whether to roll back the entire request when the delete of any object fails (default true)

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_sobjects_collections_delete.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.bulkUpdate('Contact', [{
      Id: '001xx000003DGb2AAG',
      Title: 'Lead Engineer'
    }, {
      Id: '003xx000004TmiQAAS',
      Title: 'UI Designer'
    }])
  })
  .then((data) => {
    console.log(data);
  });

composite(compositeRequest, allOrNone)

Updates a collection of records (up to 200 records).

Parameters

  • recordIds array Collection of subrequests to execute
  • allOrNone boolean Indicates whether to roll back the entire request when an error occurs while processing a subrequest (default true).

Return

Promise (for more info the response body see https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_composite_composite.htm)

Example


const { createConnection } = require('salesforceLiteConnection');

createConnection(authInfo)
  .then(conn => {
    return conn.composite([{
      method: 'POST',
      url: '/services/data/v45.0/sobjects/Account',
      referenceId: 'NewAccount',
      body: {
        Name: 'Salesforce',
        BillingStreet: 'Landmark @ 1 Market Street',
        BillingCity: 'San Francisco',
        BillingState: 'California',
        Industry: 'Technology'
      }
    }, {
      method: 'GET',
      referenceId: 'NewAccountInfo',
      url: '/services/data/v45.0/sobjects/Account/@{NewAccount.id}'
    }, {
      method: 'POST',
      url: '/services/data/v45.0/sobjects/Contact',
      body: {
        LastName: 'John Doe',
        Title: 'CTO of @{NewAccountInfo.Name}',
        MailingStreet: '@{NewAccountInfo.BillingStreet}',
        MailingCity: '@{NewAccountInfo.BillingAddress.city}',
        MailingState: '@{NewAccountInfo.BillingState}',
        AccountId: '@{NewAccountInfo.Id}',
        Email: '[email protected]',
        Phone: '1234567890'
      }
    }])
  })
  .then((data) => {
    console.log(data);
  });