Use ChatGPT to Respond to Emails in Salesforce

Don’t know what to write to a customer or a major donor? Not sure how to be kind and encourage someone to try a little harder next time? ChatGPT can do that for you. And now you can use it right inside Salesforce to respond to your emails.

My colleague Brian Ricter wrote an apex class connecting Flow with ChatGPT. It takes a string, sends that as the prompt to ChatGPT and returns the response. You can use this apex action in a flow to do anything you want with ChatGPT!

I’ve utilized Brian’s apex action in a screen flow that helps you respond to a contact’s most recent email. And I’ve packaged it up for you to install easily.

In this demo, our company sells pet rocks. We’ve received a kind email from our customer Bob. Let’s use ChatGPT to respond to Bob in a friendly way and in a flirty way.

The Good Stuff

Install this package.

View the code here.

Set up steps:

  • Prerequisites
    • Set up Gmail to Salesforce integration or another way to log incoming emails in Salesforce.
    • Sign up for a pay-as-you-go Open AI API account. I switched to a paid account about half way through testing and my bill so far is 1 cent.
  • Create a new Custom Settings record.
    • From Setup, search for Custom Settings.
    • Click on ChatGPT Settings.
    • Click Manage then Edit.
    • Paste in your API Key.
    • Paste this into Endpoint:
  • Add the Flow to your page layout.
    • Find a Contact. Click the Setup gear icon and select Edit Page.
    • Select a Flow Standard component and drag that to your page layout.
    • Select the ChatGPT Email Response Flow.
    • Click Pass record ID into this variable below the box below “recordId”
    • Save (and you may need to activate).
  • Add a Remote Site Setting.
    • From Setup, search for Remote Site Settings.
    • Click New. Give it a name and paste in the Endpoint you copied earlier. Save.
  • Optional: Edit the default signature of the email from the current user’s name.
    • Open the Flow.
    • Select the blue square labeled Modify Email if Necessary.
    • Change the value in the Sign Email From‘s Default Value.
    • Click Done, Save As, Save and Activate.

Examples, Tips and Tricks


You’re at your own risk exposing any data to ChatGPT or using the emails that it drafts. I take no responsibility for what ChatGPT does with your data or what happens if you send flirty emails from your company account! Have your legal advisor look into ChatGPT before use it with Salesforce. Always test in a sandbox.


  • Brian Ricter wrote the apex class connecting Flow with ChatGPT.
  • Rakesh Gupta, aka Automation Champion, wrote the class and test to remove HTML markup from the text. ChatGPT with API will not accept any <p> or special characters.

Published by


Jessie joined in 2018 to give introductory webinars to nonprofit customers. She now is a Senior Solution Developer supporting nonprofits and education customers at Salesforce. All opinions expressed on this blog are her own or those of the contributors. She's spent 17 years more or less in CRMs and databases, but didn't meet Salesforce until 2011. Jessie co-led the Seattle Salesforce Nonprofit User Group in 2015-2016. She wrote a sh*tty first draft of a novel and hopes to turn it into a screenplay!

Leave a Reply