> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Salesforce source

> Observe one Salesforce object or a completed Bulk query job on your app.

Use `@bijectionhq/app-rest` with the same protected `data` label on the
mount and its receivers. Use a separate mount per org, object
or bulk job.

## Declared SOQL objects

Follow [schema discovery](https://docs.bijection.com/integrations/native-rest.md#discover-and-approve-a-provider-schema)
with a bearer or OAuth2 credential authorized to describe and query the
selected sObject. Use a Salesforce My Domain and select the object by API
name, including namespace prefixes or `__c` as applicable.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const selection = {
  provider: "salesforce",
  resource: "Shipment__c",
  origin: "https://example.my.salesforce.com",
  path: "/services/data/v67.0/queryAll",
};
```

Choose a queryable sObject such as `Account`, `Contact`, `Lead`,
`Opportunity`, `Task`, `Event`, `User`, `OpportunityStage`,
`RecordType`, `Product2`, `Pricebook2`, `PricebookEntry`,
`OpportunityLineItem`, `ContentVersion`, `Attachment` or a custom
object. Use `/queryAll` for objects that expose `IsDeleted`, or `/query`
for active-only reads and objects without the deletion marker.

The proposal reads direct field names and types from the versioned
sObject Describe response. Choose up to 32 reviewed fields.
Data pages query `Id` automatically and `IsDeleted` in queryAll mode.
A full page advances by the last 18-character ID. A short page restarts
the sweep. Visible queryAll tombstones remove their keys. Omissions
leave existing rows in place. Data pages have a 36 KiB limit. Describe
responses are staged in sealed parts up to 2 MiB. Discovery refuses an
incomplete or oversized Describe response.
[Salesforce sObject Describe](https://developer.salesforce.com/docs/platform/api-rest/guide/resources-sobject-describe.html) ·
[Salesforce QueryAll](https://developer.salesforce.com/docs/platform/api-rest/guide/resources-queryall-more-results.html)

To associate Salesforce Files with one CRM record, use
`resource: "ContentDocumentLink"` and put the linked record's
18-character ID in `start`. Select fields such as `ContentDocumentId`
and `ShareType`. The app retains that parent filter on each page.
[Salesforce ContentDocumentLink](https://developer.salesforce.com/docs/platform/data-models/guide/salesforce-files.html)

## Bulk API 2.0 query results

Create a CSV `queryAll` job in Salesforce with comma delimiters and a
direct field selection that includes `Id` and `IsDeleted`. Wait for
`JobComplete`. Bind a receiver returned by
`salesforceBulkResults(myDomain, apiVersion, jobId, auth)`. Use
the API version used to create the job. Initialize with
`{ profile: { mode: "salesforceBulk", fields: ["Name"], limit: 25 } }`.
List the same extra columns as the job.

The feed pages the fixed results endpoint using Salesforce's opaque
`Sforce-Locator` and verifies each page's record count. The terminal
locator marks the feed complete. A 404 or 410 after a locator has been
committed marks a gap. Complete acquisition before Salesforce removes the
results. Cells publish as CSV text. [Salesforce Bulk query results](https://developer.salesforce.com/docs/platform/api-asynch/guide/query-get-job-results.html)

## Deletion and recovery

A row with `IsDeleted` set removes its retained record in the cursor commit.
Rows missing from a sweep or job leave prior observations in place. Purged
records can escape a `queryAll` sweep, and the feed makes no claim of
deletion history or snapshot isolation. A reset preserves accepted rows
and restarts the configured acquisition. Both modes require the release
parser artifact.

## Create, update and delete

Use `providerWriter("salesforce.sobject.create-update-delete", options, data)`
with the My Domain origin, a sealed bearer or OAuth credential and a scope
such as `["v67.0", "Account"]`. Pass it in `receivers.writers` under its mode, at the
protected `data` label. Submit one sObject field object for creates and
updates. HTTP 201 with success and the new 18-character ID acknowledges
creation. HTTP 204 acknowledges an update or delete of the supplied
18-character ID. A 404 does not acknowledge a delete. Each command has an
exact key, takes up to 24 KiB JSON and sends at most once per task.
[Salesforce sObject rows](https://developer.salesforce.com/docs/platform/api-rest/guide/resources-sobject-retrieve.html)

## Lookup and junction relationships

Bind `salesforceQuery(domain, version, auth, data)` as
`receivers.provider` and use a protected `data` label.
Initialize a dedicated mount with a declared relationship projection.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{
  profile: {
    mode: "salesforceRelationships",
    object: "CampaignMember",
    fields: [],
    lookups: [{ field: "CampaignId", object: "Campaign" }],
    junctions: [{
      name: "membership",
      from: { field: "ContactId", object: "Contact" },
      to: { field: "CampaignId", object: "Campaign" },
    }],
    limit: 10,
  },
}
```

Declare reference fields and their target sObject types as they are exposed
to the credential. The SOQL projection adds the reference fields. The edge
key contains the record ID and lookup field or junction name. When a
reference is null, the corresponding edge is removed. An observed
`IsDeleted` row removes all of its edges. Unseen records retain their edges.
Each 36 KiB page accepts up to 16 records and 16 edges per record. Records
and edges commit at the same ID-keyset position. Read edge rows through
`relationships.list` or `get`.

## Capture Files and attachments

Bind a protected `data` label and install an additional receiver at
`receivers.salesforceContent`.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { salesforceFileContentReceiver } from "@bijectionhq/app-rest";

export const fileReader = salesforceFileContentReceiver(
  "https://example.my.salesforce.com", "v67.0", auth, data,
);
```

Seal a bearer or OAuth2 credential with read access to the file records
and bodies. Select `SystemModstamp` and `ContentSize` on an internal
`ContentVersion`, or `SystemModstamp` and `BodyLength` on an
`Attachment`. Use the observed ID, timestamp and byte count with
`files.requestSalesforce({ org: "example.my.salesforce.com", api: "v67.0", object, id, stamp, size })`.
As the mount's operator, call it and `files.getSalesforce({ key })`. The deterministic capture key names the exact observed
version. A refused capture can be requested again.

The driver checks the Salesforce ID, size and timestamp before and after
reading the binary body under the reviewed org. It refuses external
Files and redirects. Up to 512 KiB can arrive in one response. Larger
Files need bounded 512 KiB ranges with exact offsets and a stable,
strong ETag. Captures are limited to 8 MiB and four concurrent jobs.
The resulting sealed File records the captured version. Provider
deletion leaves retained captures subject to the installation's file policy.
[Salesforce blob retrieve](https://developer.salesforce.com/docs/platform/api-rest/guide/dome-sobject-blob-retrieve.html)

## Submit a record for approval

Use the writer from the create, update and delete setup. Submit mode `salesforce.approvals.submit` with
`{ action: "submitApproval", id, comments? }` under an exact command key.
The sealed principal must be able to submit the named 18-character record
ID to the org's configured approval process. A successful result must match
that entity ID. `record` carries the process instance ID and `detail`
carries the returned instance state, which can be `Pending`. The receiver
declares `once`. [Process Approvals API](https://developer.salesforce.com/docs/platform/api-rest/guide/resources-process-approvals-post.html)

## Field history

Enable field history tracking on the source object and give the service
credential access to its history object. Bind
`salesforceHistory(domain, version, auth, data)` as `receivers.provider`
at a protected `data` label. For Account history, initialize with
`{ mode: "salesforceHistory", object: "AccountHistory", parentField: "AccountId", limit: 20 }`.
For a custom history object, declare its `__History` sObject name and
`ParentId` where exposed.

Read `occurrences.list` or `get`. Each capture keeps the history
ID, parent ID, timestamp, field name, and old and new values. The ID-keyset
position commits with up to 100 events and 36 KiB per page. The
terminal page restarts the query. Previously captured entries remain if
history ages out or is deleted. Availability follows Salesforce tracking
and retention.
[Salesforce history objects](https://developer.salesforce.com/docs/platform/object-reference/references/associated-objects/sforce-api-associated-objects-history.html)

## Upsert by external ID

Declare `providerWriter("salesforce.sobject.upsert", options, data)` with
the Salesforce My Domain origin, a sealed bearer or OAuth credential and
`scope: ["v68.0", "Account", "External_Id__c"]`. Pass it in
`receivers.writers` under its mode, at the protected `data` label. Use API version
46.0 or newer and configure the field as a unique External ID on the bound
sObject.

Submit the same mode under an exact command key with
`{ action: "upsert", externalId, payload }`. Use a 1–128 character URL-safe
external ID and a JSON object of fields. Omit the ID and the external ID
field from the object. An HTTP 201 with `created: true` or 200 with
`created: false` and a successful 18-character ID returns that ID in
`record` and `created` or `updated` in `detail`. A provider response
with multiple matches is unresolved by this writer. A single send per task
applies even when the external ID can be matched again.
[Salesforce external-ID API](https://developer.salesforce.com/docs/platform/api-rest/guide/dome-upsert.html)

## Bulk API 2.0 ingest

Declare `providerWriter("salesforce.bulk-ingest.upsert", options, data)`
with the My Domain origin, a sealed bearer or OAuth credential and
`scope: ["v68.0"]`. Pass it in `receivers.writers` under its mode, at the protected
`data` label. The scope fixes the
sObject and its configured unique custom External ID field.

Submit `salesforce.bulk-ingest.upsert` under an exact command key with
`{ action: "bulkIngest", object: "Account", field: "External_Id__c", records }`.
Supply 1–25 rows of `{ externalId, fields }` with case-insensitively distinct
external IDs and the same 1–16 text columns in each row. The CSV upload
fits 24 KiB. Salesforce interprets text and empty cells according to its
ingest rules.

The writer creates one job, uploads the CSV, marks the job `UploadComplete`,
then polls the retained job ID. The host sends each task at most once.
The reader checks the three job result endpoints for successful, failed and
unprocessed rows. Each result must fit 36 KiB. `outcomes` follows input order
and correlates by the external ID column. It preserves successful record IDs,
bounded failure codes when available, and the distinction between failed
and unprocessed rows. A missing result leaves the affected rows unknown.
The terminal job state appears in `detail` when collected. The job ID remains
available for provider-side inspection if response evidence is incomplete
or the 30-minute follow-up deadline expires.
[Bulk API 2.0 upsert](https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/object_reference/walkthrough_upsert.htm)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.