Put a backend you own between the agent and Salesforce. Authenticate it with a server-to-server OAuth flow as a dedicated integration user whose permission set covers only the objects and fields the workflow needs, so Salesforce enforces access on every call. Trigger it from a record-triggered Flow or an event, pass the record ID, fetch fresh context, and have the agent draft a result that a rep approves before one custom field is written. Test in a sandbox refreshed from production, watch API limits and prevent update loops.
What does connecting a custom AI agent to Salesforce involve?
Salesforce sells its own agent product, and for some teams that is the right answer. This guide is for the other case: you want a custom agent that reads Salesforce alongside your product database, contracts, call transcripts and support history, and writes back only what you have approved.
The pattern matches our HubSpot and Zendesk guides. The agent never holds a Salesforce credential. A small backend you own does, decides which objects and fields the agent may see, checks everything the agent proposes, and only then calls the Salesforce API. What is different here is how much Salesforce already enforces for you - profiles, permission sets, field-level security and sharing rules - and how many customisations sit on top of it.
The worked example is narrow on purpose: when an opportunity moves to a late stage, the agent reads the account, the open opportunity and recent activity, drafts a deal summary with risks, and saves it to one custom field after a rep approves it.
How should a custom AI agent authenticate to Salesforce?
Salesforce supports several OAuth flows. Two matter for an agent:
| Flow | Use it when | What you manage |
|---|---|---|
| Client credentials or JWT bearer (server to server) | The agent works in your own org, with no person logged in | A key or secret in a secrets manager, a run-as integration user, and rotation |
| Web server flow (authorisation code) | The agent acts as the person who clicked, or customers connect their own orgs to your product | A consent screen, a token and refresh token per user or org, and handling when access is revoked |
Salesforce has been moving from Connected Apps to External Client Apps, so check its current setup docs for what the screen is called in your org. The decision is the same either way. One org and no human in the loop: server to server with a dedicated user. Acting for individual people, or many customer orgs: authorisation code flow.
What should the agent be allowed to see and change in Salesforce?
Create a dedicated integration user for the agent and give it a permission set built for the job, not a copy of an admin profile. Salesforce then enforces object permissions, field-level security and sharing rules on every call, which is a stronger guarantee than any instruction in a prompt.
- Read: the objects and fields the workflow needs, such as Account, Opportunity, Contact and recent Tasks. Leave out fields holding data the model does not need.
- Write: one dedicated custom field for the summary, plus a Task or Note if you want an audit trail. No edits to Amount, Stage or Close Date.
- Never: delete, merge, change ownership, or touch records outside the sharing the integration user was given.
- Per-person data: if reps should only see their own accounts, run the agent as that rep through the authorisation code flow, so Salesforce applies their access rather than yours.
If your rules are more subtle than field access - for example, the agent may suggest a discount but never apply one over a threshold - enforce them in the backend as well.
How does the agent find out something changed in Salesforce?
| Route | How it works | Use it when |
|---|---|---|
| Flow or Apex callout | A record-triggered Flow calls your backend over HTTPS when a stage changes | You want a precise trigger and your admins already work in Flow. The usual starting point |
| Platform Events or Change Data Capture | Salesforce publishes events your backend subscribes to | Many record types, higher volume, or you want to avoid logic inside Salesforce |
| Scheduled query | Your backend runs a SOQL query on a schedule | Batch work such as a nightly pipeline review, or an org where you cannot add automation |
| Button or Lightning component | A rep clicks and Salesforce calls your backend | You want the agent on demand and the person in control |
Whichever you pick, send the record ID and not the whole record. The backend fetches fresh data itself, so the agent never works from a stale payload.
How do you connect a custom AI agent to Salesforce, step by step?
- 01
Work in a sandbox first
Create the integration user, permission set and app in a sandbox with realistic data. Promote the setup to production only after the workflow has run end to end there.
- 02
Create the integration user and permission set
A dedicated user with the API Enabled permission, only the objects and fields from your written contract, and nothing from an admin profile.
- 03
Register the app and store the credential
Choose the OAuth flow from the table above. Keep the secret or key in a secrets manager, never in the agent's prompt or tool definitions.
- 04
Add the trigger
A record-triggered Flow that calls your backend when an opportunity reaches the chosen stage. Pass the record ID and a shared secret or signature your backend verifies.
- 05
Fetch context in the backend
Query the account, opportunity and recent activity with the REST API, pull anything else from your own systems, and hand the agent a compact, relevant bundle rather than whole records.
- 06
Draft, approve, then write
The agent returns a summary and the facts it used. A rep sees it, edits it and approves. Only then does the backend update the one custom field, and it logs the run.
Where the agent states a fact about a deal, show where it came from, as described in how RAG citations work. Reps stop trusting a summary the first time it asserts something they cannot trace.
What goes wrong when you connect an AI agent to Salesforce?
API limits
Salesforce limits the API calls an org can make in a rolling 24 hours, and the allowance depends on edition and licences. Batch reads with SOQL and the Composite API, cache what rarely changes, and watch your usage before the agent goes live rather than after.
Automation fires in loops
Your update to a field can trigger the very Flow that called the agent. Have the Flow ignore changes made by the integration user, or check that the summary field is the only one that changed.
Custom objects and validation rules
Most orgs have years of custom fields, required-field rules and record types. A write that works in a clean sandbox can fail in production. Test against a sandbox refreshed from production, and treat a validation-rule error as a message to handle, not an outage.
Notes and call transcripts are untrusted text
A contact or an inbound email can contain instructions aimed at your agent. Keep tool access narrow and validate every action in the backend, as covered in prompt injection in AI agents.
How do you connect a custom AI agent to Salesforce?
Put a backend you own between the agent and Salesforce. Authenticate it as a dedicated integration user with a narrow permission set, trigger it from a Flow or an event, fetch fresh context by record ID, and start with drafts that a rep approves before anything is written. Test in a sandbox refreshed from production, watch API limits, and prevent update loops. Widen what the agent can change only after the approved drafts have been right for a while.
If you want an agent like this built against your own org, our AI integration team builds and connects them.
