How to Detect the Sentiment of Your Customers on Cases in Salesforce Using OpenAI

Here is a step-by-step guide on how to analyze the sentiment of your customers on cases in Salesforce.

Detect the Sentiment of Customers on Cases in Salesforce

Traditionally when a customer logs a case with the company, we have used different factors to route the cases to different support queues for resolution. Like using customer tier, customer lifetime value, their support entitlement, the nature/type/category of the case or language, geographical location etc.

One of the critical factors that have been missing is detecting the sentiment of the customer on that case. Like are they happy, angry or frustrated about your product or services?

But why is it important to detect customers sentiments?

It is important because it provides valuable insights into how customers feel about their experience with the business. By analyzing customer sentiment, businesses can better understand their customers’ needs, preferences, and pain points, and use that information to improve their products, services, and overall customer experience.

Detecting customer sentiment can also help businesses identify potential issues or trends that may be affecting multiple customers, allowing them to proactively address those issues before they escalate. Additionally, analyzing customer sentiment can help businesses identify and prioritize which cases need to be handled urgently and which ones can wait, which can improve overall efficiency and customer satisfaction.

And why is it important to prioritize handling of unhappy customers?

Unhappy customers are at a higher risk of churning or leaving your business. Studies have also shown that unhappy customers are more likely to share their negative experiences with others and leave negative reviews online, which can harm your business’s reputation and ultimately impact your bottom line.

By prioritizing unhappy customer cases, you can address their concerns and complaints in a timely and effective manner, potentially preventing them from leaving your business and even turning them into loyal customers. Additionally, addressing unhappy customer cases first shows that you value your customers and are committed to providing excellent customer service, which can help build trust and loyalty with your customer base.

How do I detect sentiments?

In the past, it was challenging for computer systems to comprehend human emotions. However, thanks to the latest advancements in AI technology, particularly in generative AI, detecting a customer’s sentiment when they log a case has become much simpler than before.

By analyzing the customer’s tone and language, it is now possible to identify if they are unhappy, angry, or frustrated. Consequently, such cases can be fast-tracked and directed to more experienced personnel who can handle them more effectively.

Here is a step-by-step guide on how to do this on a Case in Salesforce Using OpenAI

It’s time to put words into action and learn something super cool. Follow these step-by-step instructions to use OpenAI, the company behind ChatGPT, to detect the sentiment of cases created in Salesforce. Knowing the sentiment will enable you to use Salesforce’s native features to route the cases, monitor their progress, and ensure timely and effective resolution. It won’t take more than 30-40 minutes for you to get this working end-to-end in your Salesforce org.

This will help you get started. Once you get the idea of how this is done, it will be up to your imagination and creativity on how you can marry these two technologies to achieve amazing results for your business. Enjoy!

Here is what we will be covering in this guide, step-by-step:

  1. Register with OpenAI & Get API Key
  2. Prework
  3. Create Permission Set
  4. Create External Credential
  5. Create Named Credential
  6. Create Apex Class
  7. Create Screen Flow
  8. Deploy & Test the Flow

NOTE: Certain sections of the guide will appear as locked in the free preview. You can download the unlocked version of the guide in PDF format by subscribing to our “All Access” Pass through the link below.

Not an “All Access” Pass Member Yet?

Get Download Access to this & 150+ More Step-by-Step Guides with “All Access” Pass. A simple and single plan to access our entire library of courses, guides, workshops & masterclasses on Salesforce.

References & Useful URLs

12 thoughts on “How to Detect the Sentiment of Your Customers on Cases in Salesforce Using OpenAI”

  1. Pramod Mahadevan

    Thanks and I have set this up. It works fine but for some reason, the data is not populated at the first go and when I refresh the case, the information is populated. Have you faced any such situation before.

    1. Hi Pramod, yes I have noticed similar behavior. But this is at the UI level only as the data does get populated in the field on the object. It is just that it is now shown on the screen immediately.

  2. Great steps and execution. I was trying to implement this at my org, however I keep getting this error –
    Error Occurred: An Apex error occurred: System.CalloutException: We couldn’t access the credential(s). You might not have the required permissions, or the external credential “OpenAI_API_External_Credential” might not exist.

    What could be the way out?

  3. Dear Asagarwal,

    Thank you for sharing this informative post on how to detect the sentiment of customers on cases in Salesforce using OpenAI. Your step-by-step guide is easy to follow, and it’s great to see how technology can help businesses better understand their customers’ needs and emotions.

    I think that using sentiment analysis can be a game-changer for companies looking to improve customer service and satisfaction. It can help them identify common pain points, address negative feedback, and even anticipate potential issues before they arise.

    I appreciate how you’ve also included the limitations of the model and how it can be improved. It’s essential to keep in mind that AI models are not perfect and require ongoing refinement and training.

    Overall, your post provides valuable insights into how OpenAI can be used to detect sentiment in customer cases in Salesforce. Keep up the excellent work, and I look forward to reading more from you in the future!

    Best regards,
    Swami Bala

  4. Guruprasad Thande

    Hi Ashish, Return recordId is always null from the Open API callout, and i do not have any error as well in my debug screen. Is any help possible? Thanks, Guru

    OPENAIAPI (APEX): Call OpenAI API for Sentiment Analysis
    Inputs:
    caseRecords = {!recordId} (Case (5002v000038pTxWAAU))
    Outputs:
    {!recordId} = output (null)

    1. Hi Guru, one of the reasons could be that your OpenAI API Key has expired or has exceeded its allocated quote limit. If you are using a free account, there is a limit on how many calls you can make. I faced the same problem recently and this was the reason. Once I upradged my accont to paid account, it worked fine.

      To validate this, you can use a tool like “Postman” to make a call to OpenAI API using your API key and see if that returns a value.

  5. Thanks for this guide, it was clear and detailed.
    I have implemented this in my Dev org, however, the responses have been detailed even after telling the AI to return just the word “Analyze the Sentiment ….returning Happy, Neutral, Unhappy”

    I keep getting detailed results sometimes 2-3 sentences.
    Did I miss anything?

    1. Hi Nnamdi, you can try experimenting with the prompt that you are passing to OpenAI. For example, trying something like “Analyze the sentiment in following paragraph and return me one word response classifying the sentiment as Happy, Unhappy, Neutral or Undetermined”.

  6. Thanks for the helpful walkthrough– Can you please help me out a little bit, I am stuck on the debugging, the first screen shows the prefilled information however when I click next or run again it clears out all the details. Could you please advise? I am not familiar with apex classes from scratch so I am unsure if there was a step missed.

    1. Hi Anna, clicking on ‘Run Again’ in the debug mode will clear out the fields. This is normal and expected. Once you create an action button and expose it on case record, the case subject and details will be populated from the case record.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top