Sep 26, 2024
105 Views
Comments Off on Hello World Code for Salesforce Einstein
0 0

Hello World Code for Salesforce Einstein

Written by

As a programmer, We do code in many languages. We create always a program named as Hello World.

This blog is all about for Hello World program for Salesforce Einstein. In this blog, I am not going to tell you how does Salesforce Einstein work. This is just about how to get started and write your first program in Salesforce Einstein. I will cover both Salesforce Einstein Vision and Salesforce Einstein Language.

Steps:

A. Get the key:

Follow Steps from here

And read until you get the einstein_platform.pem (predictive_services.pem) file.

Note: Keep this file very carefully. Don’t loose it.

B. Upload the key file to Salesforce:

Now upload above .pem file into Salesforce org. Go to Files tab and upload this file here.(https://ap5.salesforce.com/_ui/core/chatter/files/FileTabPage – URL from my org for the File tab)

C. Remote Site Setting:

We need to add the remote site setting. See here: https://metamind.readme.io/v1/docs/apex-qs-create-remote-site

Note: As we will be using https://api.einstein.ai in EinsteinMaster class. We need to add https://api.einstein.ai in remote site instead of https://api.metamind.io

D. Copy Code:

Git Repo is here. (Salesforce-Einstein-Custom-Code https://github.com/vishnuvaishnav/Salesforce-Einstein-Custom-Code )

1. EinsteinMaster.apex: Download or Copy EinsteinMaster.apex. You don’t need to touch this file much. Just need to put the email id of yours. ( In the variable name  as USER_EMAIL). Then save it.

Note: This apex code is a combined and modified code of multiple Salesforce code files. I did some modification for the developers. So they don’t need to worry about multiple files. 

2. EinsteinExampleCtrl: Download or CopyEinsteinExampleCtrl.apex. This is example code for prediction functions. I am using 5 functions here.

  • Vision API Example – Prediction From URL: It will do prediction from given image URL.
  • Vision API Example – Prediction From Blob: It will do prediction from given Blob data ( I am using attachment’s body).
  • Vision API Example – Prediction From Base64:  It will do prediction from given Base64 data. You can generate base64.

Note: For the above 3 image vision prediction. I am using GeneralImageClassifier model. You can use your own model here. Just need to pass the Model ID in the function.

  • Language API Example – Sentiment: It will return the sentiment of given text.

Note: For the above Sentiment prediction. I am using CommunitySentiment model. You can use your own model here. Just need to pass the Model ID in the function.

  • Language API Example – Intent: It will return the intent of given text.For intent, we don’t have any predefined model. So we need to create a model for this.Read here https://metamind.readme.io/docs/intent-quick-start-custom-classifier#section-step-1-define-your-classes-and-gather-data to create an Intent model. After that pass the Model ID here.

3. EinsteinExample (VF Page): Copy this from here https://github.com/vishnuvaishnav/Salesforce-Einstein-Custom-Code/blob/master/EinsteinExample.page . It contains example of Vision API Example – Prediction From URL and Language API Example – Sentiment.

If you want to see or get the access token. You can use EinsteinMaster.getAccessToken(); in the code.

All done? Now run the page and do changes in EinsteinExampleCtrl and EinsteinExample page as per your requirement.

Cheers!!

Article Categories:
AI and ML
https://thestarbiznews.com/

Expertise: Global Macroeconomics, Business Strategy, Emerging Markets Bio: Rajeev Sharma is a seasoned investment strategist with over two decades of experience navigating the ever-evolving global market landscape. A veteran of Wall Street and a sought-after advisor to Fortune 500 companies, Rajeev brings a wealth of knowledge and expertise to TheStarBizNews. His insightful analyses of global economic trends, coupled with his keen understanding of regional specificities, provide invaluable guidance for businesses and investors alike. Fluent in four languages and a frequent speaker at international conferences, Rajeev brings a cosmopolitan flair to his writing, drawing connections between seemingly disparate events to paint a clear picture of the interconnected world we live in.