Ask ChatGPT action

DAP action

Last published at: August 8th, 2024
Delete

The Ask ChatGPT action is available for the Premium and PDM editions.

Use the Ask ChatGPT action to apply the strength of artificial intelligence to your daily operations. Use the action via the action launcher to get suggestions from ChatGPT for your specific questions related to the records you selected, or create macros with preconfigured prompts and reply-fields for repeated use in batch jobs and flows, or by your co-workers. 

Apply field variables from the object and related Salesforce objects to integrate actual Salesforce data into the dialogue with ChatGPT, and to get different answers for each record.
Ask questions about selected records, and if desired about records related to the initial records. For example, select a number of Accounts, and ask ChatGPT to summarize certain Cases related to each of those Accounts.

Store the ChatGPT responses in your Salesforce records for further processing. 

A number of examples and use cases are listed below; get more ideas for how to use the Ask ChatGPT action from our blog hereAsk ChatGPT to fill out the Department field of each selected record based on its Title field

Prerequisites

Before you can start using the Ask ChatGPT action, make sure you have done the following:

  • Subscribe to OpenAI's ChatGPT service at https://openai.com/pricing. The Ask ChatGPT action can use text-based models such as GPT-4, GPT-4 Turbo, GPT-3.5 Turbo, etc.
  • Enable remote site settings to allow Salesforce to call out to ChatGPT:
    1. Go to Salesforce Setup > Settings: Security > Remote Site Settings
    2. Click New Remote Site.
    3. Enter a name for the new remote site.
    4. At Remote Site URL, enter https://api.openai.com 
    5. Make sure the Active box is ticked. 
    6. Click Save.
  • Set up the Ask ChatGPT action settings:
    1. Go to DAP Setup. At left, go to the Action Library. At the Ask ChatGPT action, click Edit.
    2. At OpenAI API Key, enter the API Key belonging to your OpenAI subscription.
    3. At OpenAI Model, enter the API name of the OpenAI model you want to use.
      For example, enter gpt-4, gpt-4-1106-preview, or gpt-3.5-turbo.
    4. At OpenAI Temperature, enter a sampling temperature value between 0 and 2. Higher values like 1.5 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
Delete

Defining the right prompt

ChatGPT is a chatbot that will usually answer in full sentences. To have it return text that you can use in your records, you will have to tell it specifically what kind of answer you want.
For example, if you want it to return one of the values of a picklist, add a sentence to the prompt listing all values of the picklist and say that it should only return one of those values. It's best to try it out with a text field first, to see what kind of answers you will get.
Or ask it to return an answer in JSON or another format if you want to process the answer further. Ask "Make sure to return plain text, no markup" if this is important for your answer.

Add Field Variables to your prompt to use specific data from each record. See the examples below.

When adding data from related records, it is recommended to include a field variable for the related record's name, ID, or other unique field in the follow-up prompt. That way ChatGPT can distinguish between data from the different records more easily.

Note that you can enter a long prompt, but Salesforce field limits do apply.

Using the Action

  1. Select the records that you want to apply the action to in a list view, or by creating a new job.
  2. In the Action Launcher (top right in list view, or the next window in the DAP Job modal), select Ask ChatGPT and click Next.
  3. In the next window, fill in the fields:
    1. At Prompt, fill in the prompt you want to use. 
    2. Add Field Variables‍ in the prompt (optional): place the cursor at the right spot in the text and click </> Insert Field Variable  . Select the field you want to use the values of.
    3. Add data from related records (optional).
      Read more about this below at "Attach Data from Related Records". 
      1. Click + Attach Data from Related Records .
      2. At Lookup Object, select the related object to add data from.
      3. Click + Add Filter (optional) to only use certain related records.
      4. Enter a Follow-up Prompt about the related records. Use Field Variables if needed. The follow-up Prompt will be repeated for each related record, and sent to ChatGTP as one large prompt together with the main prompt.
      5. If you change your mind and do not want to use data from related records after all, click + Remove Data from Related Records  to remove the related data configuration from the action.
    4. At Result Field, select a text field or picklist where you want to record the answers as returned by ChatGPT. 
    5. The Maximum Token Response Size shows the maximum output token size based on the size of the selected Result Field. The size set here makes sure that ChatGPT does not give an answer that is larger than would fit in the result field. A larger token response size would unnecessarily use up extra tokens, as the last part of larger answers cannot be stored in the result field. You can set a smaller token response size to get smaller answers and reduce cost.
      Read more about tokens here.
    6. Click Next.
  4. In the confirmation window, check the details for the action, and click Start.

For each of the 5 selected Accounts, all related Opportunities are queried to gather information for ChatGPT to create a financial report with.

If you ran the action from a list view: once the progress bar is at 100% completed, click Finish to return to the object overview.
If you ran the action as a Job, you are returned to the Job Overview, where you can view the job results information via the Info button.

The answers that ChatGPT gave to your prompt are now saved on each record.

Delete

The Record Audit Log, if enabled, does not store the actual prompt and answer because of size limitations. It only records whether an answer was given or not.

Delete

Create a Macro

To use the action with the same prompt repeatedly, to use the action in batch jobs and flows, or to have your colleagues use the Ask ChatGPT action without them having to come up with a good prompt themselves, you can create a Macro‍. Assign the macro to users or profiles, and limit the use of the Ask ChatGPT action itself, to make sure ChatGPT is only used for certain prompts and result fields.

Combine data from records with data from their related records, and ask questions to ChatGPT based on this combined data, with the option "Attach Data from Related Records".

First you enter the main prompt, in which you can refer to information that will be gathered later on in the follow-up prompts. Then enter a follow-up prompt to gather data from the related records. It is recommended to include a field variable for the related record's name, ID, or other unique field in the follow-up prompt, so ChatGPT can distinguish between data from the different related records more easily.

Upon execution, the follow-up prompt is repeated for each of the related records. The main prompt and follow-up prompts are then sent together to ChatGPT as one API request. Do keep in mind that every OpenAI model has a context window limit.
ChatGPT answers, and the answer is stored in a field on the initial record.

For example, select a number of Accounts, and ask ChatGPT to summarize certain Cases related to each of those Accounts. The Case summaries will then be stored in a field on the Account records.

Other use cases are, again with the example of Cases related to Accounts: asking for a trend in related cases created in the past three months, the most pressing case per account, etc. Or, ask ChatGPT to analyze all related Opportunities of an Account, and to create a financial report based on its analysis. The possibilities are endless.

Well, almost endless. The maximum of related records for synchronous execution is 9,999 related records per initial record, if the chunk size is 1. For asynchronous execution this limit is higher.

Examples

Object Prompt Result Field
Case Please summarize this customer case by studying the Case Subject: "{!Subject}" and description: "{!Description}". Your response must use bullet points. Summarize in a way so that a Customer Support employer working on this case can get the essence of the case quickly. Internal Comments
Case We are are car repair shop receiving customer cases with this subject "{!Subject}" and description "{!Description}". Please choose one of the following case reasons to determine the reason for this customer case: "Installation","Equipment Complexity","Performance","Breakdown","Equipment Design","Feedback" or "Other". Your response is limited to picking one of this reasons. if you cannot determine the correct reason please pick the option "Other". Case Reason, a picklist containing the case reasons listed in the prompt
Contact Please interpret the job title "{!Title}" and choose one of the following departments which this role is part of: Human Resources, Finance, Accounting, Sales, Marketing, Customer Support, Customer Success, Information Technology, Executive Management, Other. Your response should be limited to picking one of these departments. For example, your response could be "Customer Support". Do not reply with any other words. If the job title is not part of any of these departments, reply with the word "Other". Department
Account Please write me a bulleted pitch to tell {!Name} why they need <enter your product here> to solve their <enter a problem here> issues. A text field
Account and related Opportunities Prompt:
Please generate a financial report about the following opportunity data that I will share with you, related to account {!Name}. The financial report should be interesting to a CRO persona. Please return plain text, no markup.
Follow-up Prompt:
Opportunity Name: {!Name}
Opportunity Stage: {!StageName}
Opportunity Amount: {!Amount}
Opportunity Close Date: {!CloseDate}
Opportunity Created Date: {!CreatedDate}
Opportunity Type: {!Type}
A text field

Use Cases

Watch an example of how you can combine the forces of ChatGPT and Plauti's Data Action Platform to automatically analyze contacts and set their departments:

Watch an example of how you can combine the forces of ChatGPT and Plauti's Data Action Platform to analyze Cases and set the right Department:

Use your own classes for even more options

The Ask ChatGPT action can do a lot, but it is limited to the Object fields to retrieve information from. For example, for Cases you can only use information from fields such as the Description to use in questions for ChatGPT. If you'd like to use other data sources, such as case emails for Cases, you can build your own class and action. Create a class for DAP that calls the ChatGPT API, and include all Object data you want to provide. Then run the class you created with the Run An Apex Class action. Ofcourse you can then also create a Macro for this action.

Or, to expand your options for using the ChatGPT answers, you can also implement the Ask ChatGPT action in a class, and create or update other Objects with the responses returned by ChatGPT. Send an Email Message, create a new Task, add a note to an Opportunity, the possibilities are endless. Read more about using an action in a class: Start an Action from an Apex Class.‍ 

Delete

Using ChatGPT

For subjects related to the use of ChatGPT, such as accuracy or data privacy, we kindly refer you to the information provided by OpenAI on their website.