Why is it important to detect customer sentiments in Salesforce using OpenAI? 

Introduction 

Detecting customers’ sentiments in Salesforce OpenAI is essential as it provides insights into how customers feel about their experience with the business. Analyzing customer sentiment can help businesses better understand customer needs, preferences, and pain points and enables us to determine how and where improvements are needed. With unhappy customers, I can say that businesses are at a higher risk of leaving as they may leave bad reviews; hence, analyzing customers’ tone and language helps determine if the customer is angry or frustrated, thereby helping us identify any potential issue to nip the problem in the bud.  

Why Should You Adopt Customer Sentiment Analysis?  

More than 85% of customers are likely to purchase or invest more in a company after a positive experience, while 70% are likely to decrease their investment after a negative experience. Consumers often leave comments and impressions when interacting with your brand, products, or support services. These comments can be analyzed using AI (Artificial Intelligence) tools regardless of origin.   

Customer sentiment analysis allows you to analyze any issues that customers may be having with your products or services to enable you to eliminate them. By helping you understand your customers’ likes and dislikes, you can maximize customer satisfaction by optimizing marketing campaigns, maintaining brand reputation, and fine-tuning product launches. Having access to the correct data at the right time puts you at an advantage.  

Now let me help you analyze……how automated processes help your business improve……  

What Is Customer Sentiment Analysis?  

Customer Sentiment Analysis is an automated process that allows a company to analyze customer emotions by detecting their tone when interacting with the company. It will let you know how your customers feel about your brand by identifying general emotions at a specific moment in the customer journey.   

Natural Language Processing (NLP), machine learning, and statistics can detect sentiments through patterns in text and even verbal communications. Even sarcasm can be interpreted and measure the intensity of the customer’s feelings. To improve customer satisfaction index and loyalty, customer sentiment is essential to obtain insightful information.  

For example, a study claims that customers who enjoy positive experiences spend 140% more than customers with negative experiences.  

This also considers the change in communication over the last two decades, from letters and telephone calls to a boom in communication technologies and changing lingos.  

Now, let us investigate as to how does this works for you.  

How Does Sentiment Analysis Work?  

Sentiment analysis uses machine learning, statistics, and natural language processing to determine the thoughts and feelings that people are expressing through various platforms.   
 

Rule-based sentiment analysis defines polarized words (meaning words that convey three different emotions: positive, negative, and neutral), even counts the number of these words, and recognizes the tone of the text.   

Automatic or machine learning-based models are trained with data sets that contain positive and negative words. The advantage of this model is that each word does not need to be manually input, and the models can automatically detect the tone.   

Finally, the hybrid sentiment analysis involves both manual and automatic approaches.  

There is no best way; it depends on what works for your company and business needs.   

What are the Types of Sentiment Analysis?  

There are different types of sentiment analysis that you can use:  

Intent-based sentiment analysis detects customers’ intentions towards your brand, such as whether they are interested in buying your product.   

The emotion-detection sentiment analysis uses a range of emotions such as happiness, frustration, curiosity, or even disappointment. Lexicons are used to detect the emotions present in a text.   

Aspect-based sentiment analysis helps you determine how your customers feel about your brand or specific product or service aspects.   

What are Different Ways You Can Use Sentiment Analysis to Your Advantage?  

By analyzing the product, you can understand customers’ opinions towards the product, including features such as price, quality, and packaging.  

Sentiment Analysis also includes monitoring social media platforms, including Twitter, Instagram, and Facebook, to review products. This enables you to quickly analyze years of customer feedback, respond to critical reviews, and avert PR crises.  

Finally, use sentiment analysis to track competitors’ strategies using in-depth market research, understand your competitors’ strategies, and adopt best industry practices.  

Learning about how and why customer sentiment analysis is essential does not help without knowing its benefits………true, right…. see them listed below for you…  

Benefits Of Customer Sentiment Analysis  

Using sentiment analysis to your advantage can provide many benefits to your organization. Here are ways that you can benefit from sentiment analysis:  

  1. Optimize customer service through analysis of customer service feedback. About 64% of consumers say they would stop doing business with a brand after two or three bad experiences. This also helps establish a loyal customer base.  
  1. Prepare the customer service agent with the necessary information to better prepare them to connect and empathize with the client. The issue is that 60% of customer service agents feel they need the right tools or technology to handle customer issues, and 34% cite a need for more relevant customer data as their biggest problem. According to Salesforce research, 79% of buyers say that it is essential that they interact with a salesperson they trust. This also helps with proactive crisis management.  
  1. Increase the return on investment (ROI) rate of marketing campaigns because knowing customers’ feelings can allow a business to optimize campaigns and create hyper-personalized customer experiences.  
  1. Sentiment analysis can ensure you know the characteristics of your company’s products and how people feel about them, meaning that you can provide improved products and services.  
  1. You can constantly monitor your brand reputation, which makes it possible to speed up responses to negative comments, improving brand reputation management.  
  1. By considering the omnichannel approach, fragmentation in the customer experience can be eliminated.  

Let us investigate the process of building customer sentiment analysis in Salesforce….  

A Step-By-Step Guide to Creating a Case in Salesforce Using OpenAI  

OpenAI, the company behind ChatGPT, is the mastermind behind creating the case sentiment analysis on Salesforce.   

What do you need?  

  • Salesforce Developer Edition Org or Sandbox Org  
  • Account with OpenAI  

What are the steps?  

  • Register with OpenAI and Get the API Key  
  • Navigate to the URL openai.com/blog/openai-API  
  • Sign up using the sign-up button.  
  • Click on the image icon and “View API keys.”  
  • You can see a screen titled “API Keys,” and you can “Create New Secret Key.”  
  • The API will generate a key in the text box. (Note – It is important to note here that you will not be able to view the text in the box again, so make sure you copy and paste the text to view it again.)  

What prework is needed?  

  • Here, you can create a couple of custom fields that you can use to store the sentiment-related information.  
  • On Salesforce “Setup,” create two custom fields on the Case Object of the ‘Text (255)’ type. This field will be used to make an API call to OpenAI and store the ‘sentiment’ returned by the API.  
  • The ‘Sentiment Prompt’ field will be used to instruct OpenAI to analyze the sentiment and the choice of the values that should be returned. The ‘Case Sentiment’ field will be used to store the sentiment.  
  • Have you ever used emojis to create case sentiments? Create a Formula (text) Type field to display the Emoji based on the case sentiment. You can add ‘Happy,’ ‘Unhappy,’ ‘Inquiry,’ and two different emojis for ‘neutral.’   
  • Create a new Compact Layout and add the ‘Sentiment’ field to the Compact Layout to display it in the highlights panel at the top.  
  • Create a Permission Set  
  • You will need to use ‘External Credential’ in Salesforce to authenticate OpenAI API; for that, you will need to create a Permission Set.  
  • In Setup on Salesforce, navigate to Permission Sets and click ‘New’ to create a new permission set. You can name your label & the API name. Make sure to Save it.  
  • Click ‘Manage Assignments’ to assign the permission set to the users.  
  • You can set the permission to anyone you want to have permission to the ‘Current Assignments.’  
  • Create External Credential  
  • Under Security in Setup, navigate to ‘Names Credentials. Click the ‘New’ button to create an ‘External Credential to authenticate to the Open AI API.  
  • Specify the Label, Name, and Authentication protocol and save it.  
  • Create External Credential by clicking ‘New’ under Permission Set Mappings. Under the permission Set drop-down menu, select the ‘permission set’ you created in the previous step. Identify Type should be set to ‘Named Principal.’ Save this.  
  • Under Customer Headers, click ‘New’ and Name your Custom Header. For ‘Value,’ you must name the value you copied and pasted when getting an API key from OpenAI. There should be a space between the word ‘Bearer’ and the API key. Save this.  
  • Finally, click ‘Named Credential’ and verify that you can see the values under Permission Set Mappings and Custom Headers for the External Credential.  
  • Create Named Credential  
  • To create a named credential, click ‘New’ under the Named Credentials section still under setup. Here, you can specify the Base URL for calling the API.  
  • Name your credential Open_API_Named_Credential and specify the base URL to https://api.openai.com/v1.  
  • Set the External Credential to whatever you named your Credential in the previous step.  
  • Make sure that the ‘Generate Authorization Header’ is checked. Save this.  
  • Create Apex Class  
  • Under the Apex Classes section in setup, click ‘New.’ You will need to create an Apex class to make a callout to OpenAI API and pass the case subject and description for it to analyze and return the case sentiment.  
  • In the Apex class, you can copy and paste your code. Once created, ensure you can see the Apex class in your Org.  
  • The code defines multiple things.  
  • The method ‘GetSentiment’ is defined as an Invocable Method so that it can be easily called from the Flow. The Case Record will be passed to this method as an input parameter.  
  • The second part of the lines of code prepares the request header. Ensure you are using the Named Credential you defined earlier, as it contains the base URL and the API Key for Authentication.  
  • The next part of the code prepares the request body in JSON format to send to OpenAI API. This includes the sentiment prompt, case subject, and description.  
  • The following blocks of code send the request to OpenAI API and check whether the API request was successful or not. It uses a JSON parser in Apex to extract the sentiment returned by the API.  
  • Finally, the code should ensure you return the value to the Flow.  
  • Create Screen Flow  
  •  To create a screen flow, navigate to ‘Flows’ in setup to make the Screen Flow call the Apex class for the sentiment analysis.  
  • Select ‘Screen Flow’ for Flow type and click Create.  
  • In Flow Builder, there will be a Toolbox. Under Manager, click ‘New Resource.’   
  • Set your variable as ‘Resource Type’ and ‘recordId’ as the API name. Specify the description and then the data type. RecordId is a particular variable in Salesforce flow. Salesforce automatically passes the value of the current record ID to this variable in certain areas. The variable needs to be named ‘recorded’ exactly. recordId will be used to receive the Case Record from the ‘Action’ button on the Case object.  
  • Once you scroll down, you can check the boxes’ Available for input’ and ‘Available for output.’ This is required to pass the values to the Apex class and receive the updated values back from Apex.  
  • Click on the ‘+’ icon under the start element in the screen flow and add the Screen element. The Screen element will display the Case subject and description and let users enter the prompt for sentiment analysis.  
  • You should specify the Label & API Name, then click Fields. Select the recordId resource that you created earlier for the record variable.  
  • Search for ‘Sentiment’ on a New Screen and click on the field name to add it to Canvas.  
  • Add your Subject and Description.  
  • Click on the ‘+’ icon under the screen element on your screen flow and add an Action Element to call the Apex class to make a callout to OpenAI API.  
  • Type ‘Apex’ into the search box under ‘New Action.’ You should be able to see all the Apex classes defined as ‘Invocable.’ Select the ‘Analyze Sentiment’ Apex class.  
  • Specify the Label, API Name, and Description. For Input values, toggle the switch to ‘Include.’  
  • When you scroll down, you can Pass the Case record as an input parameter to the Apex Class.  
  • Under ‘Advanced’ check ‘Manually assign variables’ to store the value returned by the Apex class in a variable in the Flow.  
  • We will use the same Case record variable for output to get the updated value back from Apex.  
  • Scroll down again to find the Transaction Control and then select the option for ‘Let the flow decide.’ Click Done.  
  •  Back on the screen flow screen, click on the ‘Copy Element’ option.  
  • Click on the ‘+’ icon below Apex Action and ‘Paste 1 Element.’ Click on the pasted element and Edit Element.  
  • On the Edit Screen, Change the Label Name to “Display Sentiment” and the API Name to “Display Sentiment.”  
  • Click on the Fields tab, specify Record Variable as ‘recorded,’ add the field ‘Case Sentiment’ to Canvas, and click done. Adding the field ‘Case Sentiment’ to Canvas will display the value returned by the Apex class.  
  • On the Screen Flow screen, click Save. When you save the Flow, Specify the Label, API Name, and description, and click Save.  
  • Click the ‘+’ icon on the Screen Flow screen and add ‘Update Records.’ You should be able to specify the label, API Name, and description. Select ‘Use the IDs and all field values from a record or record collection,’ then set the resource based on which case record will be updated. Click Done.  
  • You can test the Flow by clicking on ‘Debug’ and then click Save.  
  • The Debug Flow option will ask you to select one of the existing cases from the Org. Under the ‘Sentiment Prompt’ type, “Analyze the sentiment in the following paragraph.” Then, you can type whatever subject and description you want. The case sentiment final value should give an output of whatever the sentiment of the subject and description you gave was. For example, suppose a client gives the Subject “Having trouble submitting a case for review,” and the description is a more detailed study of the issue. In that case, the case sentiment should give the output as unhappy or frustrated. Because you have given a certain number of feelings, such as happiness, disappointment, frustration, and inquiring, these are sentiments that Flow can easily pick up. Once satisfied with all the case sentiments, you can close out of the tab.   
  • Finally, activate the Flow.  
  • Deploy and test Flow.  
  • Navigate to Object Manager in setup, then case object -> Buttons, Links, and Actions, and click New Action.  
  • Under the New Action tab, you can specify the action type as ‘Flow’ and select the Flow you created. Specify the label, and name and click save.   
  • Add the Action button to the case record page.  
  • Open any case record. If you do not define or analyze the sentiment of the case, the sentiment will show as a question mark.  
  • You can test the Flow again by adding another subject and description. When you click done, the sentiment analysis should correctly read the subject’s tone and description.  
  • You can even see the Emoji for a customer depending on what Emoji you set in the first step.  

Conclusion 

The process to install sentiment analysis to your Salesforce org may seem complicated but with the help of Prudent, you can seamlessly integrate OpenAI’s invention to detect sentiment analysis and make sure your customers get the best service possible!  

Leave A Comment