Skip to Content
Support Hub
Integrations & ActionsManaging Records with Salesforce REST API

Integrations & Actions

Managing Records with Salesforce REST API

Prerequisited

Overview

With Mavenoid, you can use Salesforce’s REST API to create, update, delete, and query records. Common use cases include querying data and interacting with objects such as Accounts, Leads, or Orders.

Configure the Integration

  1. Get an Access Token:
    Set up an OAuth 2.0 flow to receive an access token for your Salesforce instance. Use this token in API requests for secure access.

  2. API Calls Overview:

    • Salesforce REST Resources:
      Salesforce provides helpful resources for REST API Basics.

    • Salesforce API Structure:
      API requests follow the format:
      https://MyDomainName.my.salesforce.com/services/data/vXX.X/resource/, where MyDomainName is the subdomain of your Salesforce org, XX.X is the API version, and resource is the resource path.

    • Standard and Custom Objects:
      Review Standard Objects for a list of Salesforce's standard fields and objects. The Object Manager is also a helpful resource.

Examples of API Operations

Here’s how to interact with the Account object. Adjust for other objects as needed.

  • Create Records:
    Send a POST request to https://MyDomainName.my.salesforce.com/services/data/vXX.X/sobjects/Account with all required fields in the request body.

  • Update Records:
    To update a record, use a PATCH request to https://MyDomainName.my.salesforce.com/services/data/vXX.X/sobjects/Account/{ID}, where ID is the ID of the account.
     
    Note: The Call External API action does not support PATCH requests directly. To work around this, you can use a POST request with the query parameter _HttpMethod=PATCH, like so: https://MyDomainName.my.salesforce.com/services/data/vXX.X/sobjects/Account/{ID}?_HttpMethod=PATCH. Alternatively, you can use the Custom JavaScript action.

  • Read Records:
    To retrieve a specific record, send a GET request to https://MyDomainName.my.salesforce.com/services/data/vXX.X/sobjects/Account/{ID}.

  • Query Records:
    Using the Custom JavaScript action, you can run SOQL queries. For example, this query retrieves an account by email:

export async function run(
  formData: Record<string, any>,
  secrets: Record<string, string>
) {
  const customerEmail = formData["$customer-email"];
  const accessToken = formData["access-token"];

  const query = `SELECT Id FROM Account WHERE PersonEmail='${customerEmail}'`;

  const res = await fetch(
    `https://MyDomainName.my.salesforce.com/services/data/vXX.X/query?q=${encodeURIComponent(
      query
    )}`,
    {
      method: "GET",
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "User-Agent": "Mavenoid",
      },
    }
  );

  if (!res.ok) {
    return {
      ok: false,
      error: await res.text(),
    };
  }

  const data = await res.json();

  const records = data.records;

  return {
    ok: true,
    records,
  };
}

Need more help?

Ask a different questionIntegrations & Actions
Select a different product
© 2024 Mavenoid ABSitemap
Terms of servicePrivacy policyCookie policyData processing agreement