Salesforce Einstein Community Sentiment

Introduction

In this blog, I am going to explain how to analyze the text sentiment by using Salesforce Einstein Language pre-built sentiment model that allows you to classify the predict into positive, negative, neutral classes.Use the community sentiment model to classify text without building your own custom model. This model was created from data that comes from multiple sources. The data is short snippets of text, about one or two sentences, and similar to what you would find in a public community or Chatter group, a review/feedback forum, or enterprise social media. The final output looks below. You can enter the text for the prediction from the input box and you can see  Polar area chart with predictions details.

 

Prerequisites

Salesforce Einstein Platform Services APIs user OAuth token for authenticating. To generate a token, you create a JWT payload, sign the payload with your private key, and then call the API to get the token. So you need to get your own einstein_platform private key. please follow this steps to get your einstein_platform key.

  1. Go to the sign up page.
  2. Click Sign Up Using Salesforce.
  3. On the Salesforce login page, type your username and password, and click Log In.
  4. Click Allow so the page can access basic information, such as your email address, and perform requests.
  5. Download Key to save the key locally. The key file is einstein_platform.pem
  6. Upload the einstein_platform.pem key to Salesforce files.
  7. Copy JWTBearerFlow and JWT Apex Class from this git repository https://github.com/salesforceidentity/jwt

Refer this link for more information on the above steps.

Create custom metadata type or custom setting whatever works for you here to store the service endpoint, token endpoint and account details. Below is the custom metadata type which we are going to use it in this blog post.

 

 Static Resource and Remote Site Setting.

Here I am using d3.js, so upload the d3.js &d3pie.js files to the static resource as shown below.

Add remote site setting as shown below.

Code

Apex class is here below

Lightning Component.

Controller.js

helper.js