Why connect AI to Salesforce
- Sales: draft follow-up emails, summarize calls, suggest the next best action.
- Service: summarize long case histories, classify and route cases, suggest replies.
- Operations: extract data from documents and emails into the right fields.
Three ways to connect
| Option | Best for | Trade-offs |
|---|---|---|
| 1. Agentforce (Salesforce’s AI platform) | Teams that want AI agents managed inside Salesforce with built-in guardrails | Requires the right Salesforce licences; check which models are supported for your org |
| 2. Apex callouts to the OpenAI or Anthropic API | Custom actions such as a “Summarize case” button or an automated flow step | Needs development and maintenance; you manage prompts and limits |
| 3. Middleware (MuleSoft, Zapier, Make, custom services) | Simple automations across several systems | Data passes through a third party; less control inside Salesforce |
Example: an Apex callout
A common pattern: store the API endpoint and key in a Named Credential (never in code), then call it from an invocable Apex method that Flow or a button can use. Simplified example for Claude:
public with sharing class CaseSummarizer {
@InvocableMethod(label='Summarize case with AI')
public static List<String> summarize(List<String> caseTexts) {
HttpRequest req = new HttpRequest();
req.setEndpoint('callout:Anthropic_API/v1/messages'); // Named Credential
req.setMethod('POST');
req.setHeader('content-type', 'application/json');
req.setHeader('anthropic-version', '2023-06-01');
Map<String, Object> body = new Map<String, Object>{
'model' => 'YOUR_CLAUDE_MODEL',
'max_tokens' => 400,
'messages' => new List<Object>{ new Map<String, Object>{
'role' => 'user',
'content' => 'Summarize this support case in 3 bullet points: ' + caseTexts[0]
}}
};
req.setBody(JSON.serialize(body));
HttpResponse res = new Http().send(req);
// Parse res.getBody() and return the summary text
return new List<String>{ res.getBody() };
}
}The API key is added by the Named Credential’s external credential as a custom header, so it never appears in code. The same pattern works for OpenAI’s API with its own endpoint and headers.
Security and data protection
- Respect permissions: only send data the running user is allowed to see.
- Minimize and mask: send only the fields the task needs; mask personal or sensitive data.
- Use business API terms: check each provider’s data-handling terms for API use.
- Keep a human in the loop for anything customer-facing or high-impact.
- Log and monitor usage, costs and errors.
Where to start
- Pick one repetitive, high-volume task (for example case summaries).
- Build a small proof of concept on your own data.
- Measure time saved and quality, then scale.
Learn more about our Salesforce AI integration services.
Free template
FAQ
How much does AI usage cost?
You pay the AI provider for what you use. A focused use case like case summaries is usually inexpensive; we estimate costs during the proof of concept.
Which model should we start with?
Start with a fast, cost-effective model for summaries and drafts, and test a more capable one for complex reasoning.
Can AI update Salesforce records automatically?
Yes, but we recommend a human approval step for anything customer-facing or high-impact.
Does this work with Agentforce?
Yes. Many teams combine Agentforce with direct ChatGPT or Claude integrations for specific tasks.
Troubleshooting
| If this happens | Do this |
|---|---|
| Salesforce blocks the request to the AI service | Use a Named Credential for the AI endpoint so Salesforce trusts it. |
| The AI service rejects your key | Check the key stored in the External Credential and that users have access through a permission set. |
| Responses take too long | Keep prompts short, lower the maximum response length, and run longer jobs asynchronously. |
| Output is inconsistent | Give clearer instructions, an example and a fixed output format in the prompt. |