← Salesforce (REST API) + Node integrations

Run Node Code with Node API on New Updated Field on Record (of Selectable Type) from Salesforce (REST API) API

Pipedream makes it easy to connect APIs for Node, Salesforce (REST API) and 1000+ other apps remarkably fast.

Trigger workflow on
New Updated Field on Record (of Selectable Type) from the Salesforce (REST API) API
Next, do this
Run Node Code with the Node API
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜

Trusted by 400,000+ developers from startups to Fortune 500 companies

Adyen logo
Brex logo
Carta logo
Checkr logo
Chameleon logo
DevRev logo
LinkedIn logo
Netflix logo
New Relic logo
OnDeck logo
Replicated logo
Scale AI logo
Teamwork logo
Warner Bros. logo
Xendit logo

Developers Pipedream

Getting Started

This integration creates a workflow with a Salesforce (REST API) trigger and Node action. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Select this integration
  2. Configure the New Updated Field on Record (of Selectable Type) trigger
    1. Connect your Salesforce (REST API) account
    2. Configure timer
    3. Select a Object Type
    4. Select a Field
    5. Optional- Configure Field Updated to
  3. Configure the Run Node Code action
    1. Connect your Node account
  4. Deploy the workflow
  5. Send a test event to validate your setup
  6. Turn on the trigger

Details

This integration uses pre-built, source-available components from Pipedream's GitHub repo. These components are developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

Trigger

Description:Emit new event (at regular intervals) when a field of your choosing is updated on any record of a specified Salesforce object. Field history tracking must be enabled for the chosen field. See the docs on [field history tracking](https://sforce.co/3mtj0rF) and [history objects](https://sforce.co/3Fn4lWB) for more information.
Version:0.1.5
Key:salesforce_rest_api-updated-field-on-record

Trigger Code

import startCase from "lodash/startCase.js";

import common from "../common.mjs";
const { salesforce } = common.props;

/**
 * Uses the Salesforce REST API's [sObject Get Updated endpoint](https://sforce.co/3yPSJZy) on the
 * [StandardObjectNamedHistory model](https://sforce.co/3Fn4lWB) to get changes to field values of
 * an sObject type. Associated sObject records are retrieved and emitted for history object records
 * matching configured `field` and `fieldUpdatedTo` prop values.
 */
export default {
  ...common,
  type: "source",
  name: "New Updated Field on Record (of Selectable Type)",
  key: "salesforce_rest_api-updated-field-on-record",
  description: "Emit new event (at regular intervals) when a field of your choosing is updated on any record of a specified Salesforce object. Field history tracking must be enabled for the chosen field. See the docs on [field history tracking](https://sforce.co/3mtj0rF) and [history objects](https://sforce.co/3Fn4lWB) for more information.",
  version: "0.1.5",
  props: {
    ...common.props,
    objectType: {
      type: common.props.objectType.type,
      label: common.props.objectType.label,
      description: common.props.objectType.description,
      async options(context) {
        const { page } = context;
        if (page !== 0) {
          return {
            options: [],
          };
        }

        const { sobjects } = await this.salesforce.listSObjectTypes();
        // Filter options to include only sObjects with associated
        // [history](https://sforce.co/3Fn4lWB) objects
        const options = sobjects
          .filter(this.isValidSObject)
          .map((sobject) => ({
            label: sobjects.find((o) => o.name === sobject.associateParentEntity).label,
            value: sobject.associateParentEntity,
          }));
        return {
          options,
        };
      },
    },
    field: {
      propDefinition: [
        salesforce,
        "field",
        ({ objectType }) => ({
          objectType,
        }),
      ],
    },
    fieldUpdatedTo: {
      propDefinition: [
        salesforce,
        "fieldUpdatedTo",
      ],
    },
  },
  hooks: {
    ...common.hooks,
    async activate() {
      await common.hooks.activate.call(this);
      const historyObject = await this.salesforce.getHistorySObjectForObjectType(this.objectType);
      if (!historyObject) {
        throw new Error(`History object not found for "${this.objectType}"`);
      }
      this._setHistoryObjectType(historyObject.name);
    },
  },
  methods: {
    ...common.methods,
    _getHistoryObjectType() {
      return this.db.get("historyObjectType");
    },
    _setHistoryObjectType(historyObjectType) {
      this.db.set("historyObjectType", historyObjectType);
    },
    _getParentId(item) {
      const parentIdKey = `${this.objectType}Id`;
      return item[parentIdKey] ?? item["ParentId"];
    },
    isValidSObject(sobject) {
      // Only the activity of those SObject types that have the `replicateable`
      // flag set is published via the `getUpdated` API.
      //
      // See the API docs here: https://sforce.co/3gDy3uP
      return sobject.replicateable && this.salesforce.isHistorySObject(sobject);
    },
    isRelevant(item) {
      const isFieldRelevant = item.Field === this.field;
      const isFieldValueRelevant = !this.fieldUpdatedTo || item.NewValue === this.fieldUpdatedTo;
      return isFieldRelevant && isFieldValueRelevant;
    },
    generateMeta(event) {
      const nameField = this.getNameField();
      const {
        record: item = {},
        update,
      } = event;
      const { [nameField]: name } = item;
      const {
        Id: id,
        CreatedDate: createdDate,
      } = update;
      const entityType = startCase(this.objectType);
      const summary = `${this.field} on ${entityType}: ${name}`;
      const ts = Date.parse(createdDate);
      const compositeId = `${id}-${ts}`;
      return {
        id: compositeId,
        summary,
        ts,
      };
    },
    async processEvent(eventData) {
      const {
        startTimestamp,
        endTimestamp,
      } = eventData;
      const historyObjectType = this._getHistoryObjectType();
      const {
        ids,
        latestDateCovered,
      } = await this.salesforce.getUpdatedForObjectType(
        historyObjectType,
        startTimestamp,
        endTimestamp,
      );
      this.setLatestDateCovered(latestDateCovered);

      // By the time we try to retrieve an item, it might've been deleted. This
      // will cause `getSObject` to throw a 404 exception, which will reject its
      // promise. Hence, we need to filter those items that are still in Salesforce
      // and exclude those that are not.
      const historyItemRetrievals = await Promise.allSettled(
        ids.map((id) => this.salesforce.getSObject(historyObjectType, id)),
      );
      const historyItems = historyItemRetrievals
        .filter((result) => result.status === "fulfilled")
        .map((result) => result.value)
        .filter(this.isRelevant);

      // To fetch associated sObject records only once, create a set of the "parent IDs" of the
      // history object records
      const parentIdSet = new Set(
        historyItems
          .map(this._getParentId)
          .filter((id) => id),
      );
      const parentIds = Array.from(parentIdSet);

      const itemRetrievals = await Promise.allSettled(
        parentIds.map((id) => this.salesforce.getSObject(this.objectType, id)),
      );
      const itemsById = itemRetrievals
        .filter((result) => result.status === "fulfilled")
        .map((result) => result.value)
        .reduce((acc, item) => {
          acc[item.Id] = item;
          return acc;
        }, {});

      const events = historyItems.map((item) => ({
        update: item,
        record: itemsById[this._getParentId(item)],
      }));

      events.forEach((event) => {
        const meta = this.generateMeta(event);
        this.$emit(event, meta);
      });
    },
  },
};

Trigger Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
Salesforce (REST API)salesforceappThis component uses the Salesforce (REST API) app.
N/Adb$.service.dbThis component uses $.service.db to maintain state between component invocations.
timer$.interface.timer
Object TypeobjectTypestringSelect a value from the drop down menu.
FieldfieldstringSelect a value from the drop down menu.
Field Updated tofieldUpdatedTostring

If provided, the trigger will only fire when the updated field is an EXACT MATCH (including spacing and casing) to the value you provide in this field

Trigger Authentication

Salesforce (REST API) uses OAuth authentication. When you connect your Salesforce (REST API) account, Pipedream will open a popup window where you can sign into Salesforce (REST API) and grant Pipedream permission to connect to your account. Pipedream securely stores and automatically refreshes the OAuth tokens so you can easily authenticate any Salesforce (REST API) API.

Pipedream requests the following authorization scopes when you connect your account:

About Salesforce (REST API)

Web services API for interacting with Salesforce

Action

Description:Write custom Node.js code and use any of the 400k+ npm packages available. Refer to the [Pipedream Node docs](https://pipedream.com/docs/code/nodejs) to learn more.
Version:0.0.2
Key:node-run-node-code

Action Code

import node from "../../node.app.mjs";

export default {
  name: "Run Node Code",
  version: "0.0.2",
  key: "node-run-node-code",
  description: "Write custom Node.js code and use any of the 400k+ npm packages available. Refer to the [Pipedream Node docs](https://pipedream.com/docs/code/nodejs) to learn more.",
  props: {
    node,
  },
  type: "action",
  methods: {},
  async run({
    steps, $,
  }) {
    // Return data to use it in future steps
    return steps.trigger.event;
  },
};

Action Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI.

LabelPropTypeDescription
NodenodeappThis component uses the Node app.

Action Authentication

The Node API does not require authentication.

About Node

Anything you can do with Node.js, you can do in a Pipedream workflow. This includes using most of npm's 400,000+ packages.

More Ways to Connect Node + Salesforce (REST API)

Run Node Code with Node API on Updated Field on Record (Instant, of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Node
 
Try it
Run Node Code with Node API on New Object (Instant, of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Node
 
Try it
Run Node Code with Node API on New Object (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Node
 
Try it
Run Node Code with Node API on Object Deleted (Instant, of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Node
 
Try it
Run Node Code with Node API on Object Deleted (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Node
 
Try it
New Deleted Object (Instant, of Selectable Type) from the Salesforce (REST API) API

Emit new event immediately after an object of arbitrary type (selected as an input parameter by the user) is deleted

 
Try it
New Deleted Object (of Selectable Type) from the Salesforce (REST API) API

Emit new event (at regular intervals) when an object of arbitrary type (selected as an input parameter by the user) is deleted. See the docs for more information.

 
Try it
New Object (Instant, of Selectable Type) from the Salesforce (REST API) API

Emit new event immediately after an object of arbitrary type (selected as an input parameter by the user) is created

 
Try it
New Object (of Selectable Type) from the Salesforce (REST API) API

Emit new event (at regular intervals) when an object of arbitrary type (selected as an input parameter by the user) is created. See the docs for more information.

 
Try it
New Outbound Message (Instant) from the Salesforce (REST API) API

Emit new event when a new outbound message is received in Salesforce. See Salesforce's guide on setting up Outbound Messaging. Set the Outbound Message's Endpoint URL to the endpoint of the created source. The "Send Session ID" option must be enabled for validating outbound messages from Salesforce.

 
Try it
Add Contact to Campaign with the Salesforce (REST API) API

Adds an existing contact to an existing campaign. See Event SObject and Create Record

 
Try it
Add Lead to Campaign with the Salesforce (REST API) API

Adds an existing lead to an existing campaign. See Event SObject and Create Record

 
Try it
Convert SOAP XML Object to JSON with the Salesforce (REST API) API

Converts a SOAP XML Object received from Salesforce to JSON

 
Try it
Create Account with the Salesforce (REST API) API

Creates a Salesforce account, representing an individual account, which is an organization or person involved with your business (such as customers, competitors, and partners). See Account SObject and Create Record

 
Try it
Create Attachment with the Salesforce (REST API) API

Creates an attachment, which represents a file that a User has uploaded and attached to a parent object. See Attachment SObject and Create Record

 
Try it