Everyone is working out what AI can actually do inside their daily workflows. Drafting emails is the obvious one. But once ChatGPT is connected to Salesforce Flow, it can sit inside any process you automate, reading your data and writing results back to records.
This guide covers how to set up the connection. To see what you can do with it, read Leveraging AI for process automation, with three real use cases and demos.
How the connection works
Flow can call an outside API directly with an HTTP Callout action, with no Apex required. The pieces:
- An OpenAI API key. Create one in your OpenAI account, and set a monthly spending limit there so a runaway flow can't run up a bill.
- An External Credential in Setup that stores the key securely. Use the Custom authentication protocol, add a principal with an
ApiKeyparameter, and add a custom header that sends it:
Authorization: {!'Bearer ' & $Credential.OpenAI.ApiKey}- A Named Credential pointing to
https://api.openai.comthat uses the External Credential. The key never appears in your flow. - A permission set that grants access to the External Credential principal, assigned to the users (or the automated process user) that run the flow.
- An HTTP Callout action in Flow Builder that uses the Named Credential and posts to the chat completions endpoint. You give Flow a sample request and response, and it generates typed variables you can use in the rest of the flow.
A sample request, here asking the model to classify a job title:
POST /v1/chat/completions
{
"model": "<your chosen model>",
"temperature": 0.2,
"max_tokens": 300,
"messages": [
{ "role": "system", "content": "Classify job titles. Reply with JSON only." },
{ "role": "user", "content": "Title: VP, Global Revenue Operations" }
]
}And the part of the response your flow reads:
{
"choices": [
{ "message": { "role": "assistant",
"content": "{\"function\": \"Operations\", \"level\": \"VP\"}" } }
],
"usage": { "prompt_tokens": 31, "completion_tokens": 14 }
}The answer is in choices[0].message.content. Asking for JSON, as above, makes it easy to split the answer into separate fields on the record.
Build it to last
- Log every call. Save the prompt, the response, and the token counts to a custom object. You'll want the history for troubleshooting, cost tracking, and trust.
- Keep prompts in configuration, not in flows. A prompt library in custom metadata or a custom object lets you improve prompts, and switch models, without editing the automation.
- Control temperature and tokens per use case. Low temperature for classification and data cleanup, higher for drafting text.
- Be deliberate about data. Only send the fields the task needs, and check your company's policy on sending customer data to an outside AI provider.
Where to start
Pick one repetitive task where people currently read something and make a judgment: classifying, summarizing, cleaning up data, or drafting a first response. Those are where AI in your workflow pays off fastest. For ideas, see three use cases we have built.
We can connect ChatGPT to your Salesforce and build your first use case quickly, with logging and configurable prompts from day one. Book a free strategy session to talk it through.
