Skip to content

Add Salesforce worker sync example - #15

Open
thisisgoldman wants to merge 1 commit into
mainfrom
add-salesforce-worker-example
Open

Add Salesforce worker sync example#15
thisisgoldman wants to merge 1 commit into
mainfrom
add-salesforce-worker-example

Conversation

@thisisgoldman

Copy link
Copy Markdown
Contributor

Summary

Replaces the placeholder at examples/workers/syncs/salesforce/ with a working Notion worker that one-way syncs Accounts and Opportunities from Salesforce into Notion via OAuth.

  • worker.oauth("salesforceAuth") (Web Server Flow) — the runtime stores and refreshes tokens.
  • Two managed databases joined by a two-way relation (Schema.relation("accounts", { twoWay: true, relatedPropertyName: "Opportunities" })).
  • Backfill + delta sync pair per object (4 syncs total) reuses the helpers runBackfillCycle / runDeltaCycle so each registration is ~6 lines.
  • accessToken() only returns the bearer, so salesforce.ts calls /services/oauth2/userinfo once per invocation to discover the org's instance URL.

Test plan

  • npm install && npm run check in examples/workers/syncs/salesforce/
  • Create a Connected App with the redirect URL from ntn workers oauth show-redirect-url
  • ntn workers env set SF_CLIENT_ID=... SF_CLIENT_SECRET=...
  • ntn workers deploy --name salesforce-sync
  • ntn workers oauth start salesforceAuth
  • ntn workers sync trigger accountsBackfill && ntn workers sync trigger opportunitiesBackfill
  • Confirm both databases populate and each Opportunity row links to its Account via the relation column
  • Edit an Account and an Opportunity in Salesforce; trigger the deltas and confirm updates flow through

🤖 Generated with Claude Code

Replaces the placeholder with a working Notion worker that one-way syncs
Salesforce Accounts and Opportunities into two related managed Notion
databases via OAuth 2.0.

- worker.oauth("salesforceAuth") with Web Server Flow; the runtime
  refreshes tokens automatically.
- Two managed databases joined by a two-way relation
  (Accounts ↔ Opportunities, related property "Opportunities").
- Four syncs (backfill+delta per object) share one pacer; the backfill
  replace-mode handles deletes via mark-and-sweep.
- accessToken() only returns the bearer, so salesforce.ts discovers the
  org's instance URL via /services/oauth2/userinfo and caches it for
  the lifetime of the invocation.

README walks through Connected App creation, OAuth redirect URL setup,
scopes, and the ntn workers oauth start step.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant