← Salesforce (REST API)

New Updated Field on Record (of Selectable Type) from Salesforce (REST API) API

Pipedream makes it easy to connect APIs for 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
Connect to 1000+ APIs using code and no-code building blocks
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜

Trusted by 500,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

Trigger a workflow on New Updated Field on Record (of Selectable Type) with Salesforce (REST API) API. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. 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
  2. Add steps to connect to 1000+ APIs using code and no-code building blocks
  3. Deploy the workflow
  4. Send a test event to validate your setup
  5. Turn on the trigger

Integrations

Send Message with Discord Webhook API on Updated Field on Record (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Discord Webhook
 
Try it
Add Multiple Rows with Google Sheets API on Updated Field on Record (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Google Sheets
 
Try it
Get Film with SWAPI - Star Wars API on Updated Field on Record (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + SWAPI - Star Wars
 
Try it
Create Multiple Records with Airtable API on Updated Field on Record (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + Airtable
 
Try it
Chat with OpenAI (ChatGPT) API on New Updated Field on Record (of Selectable Type) from Salesforce (REST API) API
Salesforce (REST API) + OpenAI (ChatGPT)
 
Try it

Details

This is a pre-built, source-available component from Pipedream's GitHub repo. The component is 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.

New Updated Field on Record (of Selectable Type) on Salesforce (REST API)
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

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);
      });
    },
  },
};

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 executions.
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

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

More Ways to Use Salesforce (REST API)

Triggers

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

Actions

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