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

sf-composite-call

v0.6.1

Published

Support for making Salesforce composite call requests with integration for JSforce.

Downloads

3,468

Readme

Salesforce Composite Call

A library for dealing with the Composite Call API in Salesforce. Integrates with the JSforce node module when available and passed as an option.

Usage

Install it from the npm repository:

npm install --save sf-composite-call

Then require it in your project:

const escape = require('escape-html')
const { Connection } = require('jsforce')
const { CompositeCall } = require('sf-composite-call')
const util = require('util')
const getToken = util.promisify(
  require('salesforce-jwt-bearer-token-flow').getToken
)

async function main () {
  // Build an authenticated connection with Salesforce.
  // Note: Example uses JWT, but your jsforce connection may vary depending on your use case.
  const jwt = await getToken({
    iss: 'Replace this with your Client Id from Salesforce',
    sub: 'Replace this with your username from Salesforce',
    aud: 'https://login.salesforce.com',
    privateKey: 'Replace with your private pem certificate'
  })

  const conn = new Connection({
    instanceUrl: jwt.instance_url,
    accessToken: jwt.access_token
  })

  // Create the composite call.
  // Note: Order of operations matter when making composite calls.
  const compositeCall = new CompositeCall({
    allOrNone: true,
    jsforceConnection: conn
  })
  const account = compositeCall.addSObject('Account')
  const accountNote = compositeCall.addSObject('ContentNote')
  const accountNoteLink = compositeCall.addSObject('ContentDocumentLink')

  // Note: More fields may be required to create an account sObject in your Salesforce instance.
  account.create({
    Name: 'Some account name'
  })
  accountNote.create({
    Title: 'Some note title',
    Content: Buffer.from(escape("Here's some note content"), 'utf8').toString(
      'base64'
    )
  })

  // Note: Pay special attention to usage of references. In this example accountNote must be part of the same composite call otherwise an error is thrown.
  accountNoteLink.create({
    ContentDocumentId: `@{${accountNote.referenceId}.id}`,
    LinkedEntityId: `@{${account.referenceId}.id}`
  })

  // Execute the composite call.
  const result = await compositeCall.execute()
}

main()

The TypeScript code is compiled to JavaScript and distributed via NPM. If you wish to use the TypeScript code directly you can download the zip and unpack it locally.

Then import it in your project:

import { CompositeCall } from './sf-composite-call/index.ts'

JSforce is not a required module. This library can be used to simply build out the requests so that another JavaScript API can make the actual POST operation using fetch() or request or whatever framework makes you happy.

Options

The entire options object can be omitted when creating a new instance of CompositeCall.

| Option | Type | Description | | :--------------------: | ------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | allOrNone | Boolean | Optional. Used in the request to Salesforce. See their documentation | | collateSubrequests | Boolean | Optional. Used in the request to Salesforce. See their documentation | | version | String | Optional Sets the version of the Salesforce API to use for the Composite Call; defaults to v48.0. | | jsforceConnection | JSforce instance | Optional. This connection enables the execute() method for convenience. Without it, the result of Composite Call will have to be passed to another method to post it to Salesforce. |

Documentation

The API is fully documented internally. Raw methods are available in most cases in the event that things like the url or the body of the message need to be manipulated further, or some operation is supported by Salesforce that is not directly implemented by this library.

Further documentation of Salesforce Composite Calls can be found at their site. As much effort as possible has been taken to make this an implementation of their JSON request/response API in JavaScript.