50,39 €
Incorporate the power of Einstein in your Salesforce application
This book is for developers, data scientists, and Salesforce-experienced consultants who want to explore Salesforce Einstein and its current offerings. It assumes some prior experience with the Salesforce platform.
Dreamforce 16 brought forth the latest addition to the Salesforce platform: an AI tool named Einstein. Einstein promises to provide users of all Salesforce applications with a powerful platform to help them gain deep insights into the data they work on.
This book will introduce you to Einstein and help you integrate it into your respective business applications based on the Salesforce platform. We start off with an introduction to AI, then move on to look at how AI can make your CRM and apps smarter. Next, we discuss various out-of-the-box components added to sales, service, marketing, and community clouds from salesforce to add Artificial Intelligence capabilities. Further on, we teach you how to use Heroku, PredictionIO, and the force.com platform, along with Einstein, to build smarter apps.
The core chapters focus on developer content and introduce PredictionIO and Salesforce Einstein Vision Services. We explore Einstein Predictive Vision Services, along with analytics cloud, the Einstein Data Discovery product, and IOT core concepts. Throughout the book, we also focus on how Einstein can be integrated into CRM and various clouds such as sales, services, marketing, and communities.
By the end of the book, you will be able to embrace and leverage the power of Einstein, incorporating its functions to gain more knowledge. Salesforce developers will be introduced to the world of AI, while data scientists will gain insights into Salesforce's various cloud offerings and how they can use Einstein's capabilities and enhance applications.
This book takes a straightforward approach to explain Salesforce Einstein and all of its potential applications. Filled with examples, the book presents the facts along with seasoned advice and real-world use cases to ensure you have all the resources you need to incorporate the power of Einstein in your work.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 234
Veröffentlichungsjahr: 2017
BIRMINGHAM - MUMBAI
Copyright © 2017 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavoured to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2017
Production reference: 1240617
ISBN 978-1-78712-689-3
www.packtpub.com
Author
Mohith Shrivastava
Copy Editor
Zainab Bootwala
Reviewer
Raghuver Parupalli
Project Coordinator
Prajakta Naik
Commissioning Editor
Aaron Lazar
Proofreader
Safis Editing
Acquisition Editor
Angad Singh
Indexer
Pratik Shirodkar
Content Development Editor
Lawrence Veigas
Graphics
Abhinash Sahu
Technical Editor
Tiksha Sarang
Production Coordinator
Deepika Naik
Mohith Shrivastava has been working with Salesforce and Force.com since 2011, after he graduated from the National Institute of Engineering, Mysore.
He is currently 20X Salesforce certified and a Salesforce MVP. He has been actively contributing to Salesforce Stack Exchange. He loves coding on the SFDC platform and is skilled in Salesforce-specific languages, such as Apex, Visualforce, and the Lightning Component framework.
Mohith has authored Salesforce Essentials For Administrators for Packt, and he was also a technical reviewer for the book, Developing Applications with Salesforce Chatter. In his free time, he loves watching cricket and movies, hanging out with friends, and exploring the latest technologies related to web, mobile, and IoT.
Raghuver Parupalli is a Salesforce System Architect working at a US Federal Agency. He worked on multiple projects in various sectors, such as federal government, finance, and non-profits. He is a proud alumni of the University of Houston. He holds multiple certifications from Salesforce and is a certified Scrum Master. He is also a co-leader of the Washington DC Salesforce Developer meetup.
Raghu has deep interest in Salesforce, data analytics, AI, and machine learning concepts.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Thanks for purchasing this Packt book. At Packt, quality is at the heart of our editorial process. To help us improve, please leave us an honest review on this book's Amazon page at https://www.amazon.com/dp/1787126897.
If you'd like to join our team of regular reviewers, you can e-mail us at [email protected]. We award our regular reviewers with free eBooks and videos in exchange for their valuable feedback. Help us be relentless in improving our products!
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
Introduction to AI
Artificial Intelligence key terms
Machine Learning
Neural networks
Deep Learning
Natural language processing
Cognitive computing
Pattern recognition
Data mining
GPUs
Programming languages used for machine learning
Practical machine learning with Google Prediction API and Salesforce
Business scenario
Prerequisites
Training and prediction
Integration architecture
Setting authentication for calling API from SFDC
Drawback of this approach
Summary
Role of AI in CRM and Cloud Applications
Sales Cloud Einstein offerings
Automated Activity Capture
Lead Insights
Opportunity Insights
Account Insights
Community Cloud Einstein features
The Company Highlights feature on Chatter
Unanswered questions component for Community Builder
Creating Salesforce Communities
Recommended experts, articles, and topics
Marketing Cloud Einstein features
Social Studio Einstein features
Personalization Builder
Summary
Building Smarter Apps Using PredictionIO and Heroku
Introduction to PredictionIO
PredictionIO platform components
Architecture and integration with applications
Integration with web/mobile applications
Installation of PredictionIO
Prerequisites
Installing and configuring PredictionIO Event Server
Getting started with PredictionIO
PredictionIO DASE components and customization of Engine
Engine design
Query data structure
Predicted response design
Spark MLlib
Data
Algorithm
Serving
Deploying PredictionIO on Heroku
Heroku Buildpack for PredictionIO
Deploying an Event Server application
Deploying the Template Engine
Summary
Product Recommendation Application using PredicitionIO and Salesforce App Cloud
Introduction to Spark MLlib
Setting up the Event Server app on Heroku
Event Server code explanation
Setting up the Recommendation engine application on Heroku
PredictionIO Engine template code explanation
ServerApp
TrainApp
Setting up IntelliJ IDEA IDE for customizing PredictionIO application
Introduction to building Lightning Component for App Cloud and Community Cloud
Visualforce
Lightning Component framework
Component
JavaScript controller
JavaScript Helper
Component CSS file
Apex controller class
Building similar Recommendation Lightning Component for App Cloud
Custom settings for configuration parameters
The ProductViewCapture component
The SimilarProductRecommender component
PredictionIO commands cheat sheet
GitHub references
Summary
Salesforce Einstein Vision
Signing up for Einstein Vision account
Explore Einstein Vision APIs
Creation of dataset
Creating a dataset from a zip file asynchronously
Get status of the upload
Train the dataset
Get status of the training
Prediction with image file
Set up the Heroku add-on for Einstein Vision Services
Authorization setup
Procfile
Obtaining the access token from Private Key
Building Node.js application using Einstein Vision on Heroku using React
Building React UI for image upload
Scaffolding a React App
The index.js file
The App.js file
The results.js file
Middleware using Express
The Episode7 module
The update-token.js file
The fileupload.js file
Testing the application on localhost
Deployment on Heroku instance
Limitations of the application
Summary
Building Applications Using Einstein Vision and Salesforce Force.com Platform
Set up authorization between Salesforce and Einstein Vision APIs
Remote Site settings for Einstein API
Securing Private Key
Apex code utility to obtain access token
Constructing JWT Encoded Body
JWT Bearer token exchange
Creating and training dataset via Apex
Creating dataset using Apex
Monitoring status of training
Train dataset using Apex
Creating an administration app for creating and training dataset
Data model
Application and tabs
Trigger automation for dataset creation and training the model
Creating Lightning Components to recognize image
Summary
Einstein for Analytics Cloud
Setting up Wave Analytics Cloud
Enabling access and permissions to the Analytics Cloud
Creating and assigning permission sets
Creating datasets, lenses, and dashboards
Creating a dataset
Dataflow and data manager
Creating a lens from dataset
Creating interactive dashboards
Scheduling dataflow
Using transformations to create dataset
The sfdcDigest transformation
The sfdcRegister transformation
The append transformation
The augment transformation
The computeExpression transformation
The computeRelative transformation
The delta transformation
The dim2mea transformation
The edgemart transformation
The filter transformation
The flatten transformation
The sliceDataset transformation
An update transformation
Wave Analytics SAQL, XMD 2.0, and dataset Row-Level Security
Salesforce Analytics Query Language
XMD 2.0
Row-level Security for dataset
Introduction to Einstein Data Discovery
Sign up for a trial organization
Importing Salesforce data into Einstein Data Discovery and creating stories
Creating datasets from Salesforce objects
Creating stories
Summary
Einstein and Salesforce IoT Cloud Platform
IoT Cloud key terms
State machine
Orchestration
Traffic view
IoT Cloud components
Input streams and data connections
Data Pipes and data transformation
Orchestrations
Apache Kafka on Heroku
Kafka API
Apache Kafka on Heroku
Supported languages
Node.js sample code for producers and consumers
Encrypting the connection between Kafka and the Heroku web app
Import the Kafka Node.js module
Initializing producer in your Node.js application
Publish interaction events to Kafka
Consuming Kafka messages
IoT integration on the Salesforce Force.com platform
Introducing platform events
Creating platform events
Publish platform events
Subscribe to the platform events
Using CometD to subscribe to platform events
Writing unit Apex tests for platform events
Introducing identity for the Internet of Things
OAuth 2.0 Asset Token Flow for securing connected devices
Prerequisites for implementing asset token flow in Salesforce
Asset token explorer app
OAuth 2.0 authentication flow for applications on limited input devices
Request and Response for device initiating authentication flow
Request and Response samples for polling the token endpoint
Using PredictionIO on IoT events
Summary
Measuring and Testing the Accuracy of Einstein
Measuring the accuracy of Sales Cloud Einstein
Measuring the accuracy of the Einstein Lead Scoring engine
Which lead field values affect conversion rates the most?
Salesforce report to measure the accuracy of Lead Score
Measuring the accuracy of Opportunity Insights
Building evaluation metrics for the PredictionIO systems
ML tuning and evaluation in PredictionIO
Cross Validation
Building the PredictionIO evaluation module
Accuracy
Precision and recall
The f1 score
The confusion matrix
Evaluation in PredictionIO
Measuring the accuracy of Salesforce Einstein Vision
The Get model metrics
The Get model learning curve
Summary
Artificial Intelligence is empowering a variety of web and mobile applications, making them smarter and predictable. Salesforce Einstein from Salesforce brings Artificial Intelligence to its variety of cloud offerings, adding intelligence. With Einstein added to sales, service, marketing, Community Cloud, Analytics Cloud, and IoT Cloud, enterprises can leverage the power of artificial intelligence with the Salesforce data out of box without the need for data scientists. Because Einstein services are on cloud, this avoids having to set up and maintain any hardware infrastructure.
Einstein for developers offers APIs for image recognition, and with the PredictionIO framework offered by Einstein, developers can use out-of-the-box templates provided by the PredictionIO framework to create predictive engines for any machine learning task. The primary intent of this book is to cover the breadth of Salesforce Einstein. For Salesforce developers, the book provides a comprehensive coverage of what's currently available as a part of the Einstein offering, and how they can integrate with Salesforce data. For data scientists, it gives an overview of Salesforce Cloud offerings, and how machine learning is baked into the offerings.
Chapter 1, Introduction to AI, familiarizes you with basic terminologies used in the field of Artificial Intelligence. Learn the basics of the machine learning system by doing a small activity and integrating Salesforce with Google Machine Learning Services.
Chapter 2, Role of AI in CRM and Cloud Applications, covers a few out-of-the-box AI components from sales, service, marketing, Analytics Cloud, and Community Cloud offerings.
Chapter 3, Building Smarter Apps Using PredictionIO and Heroku, teaches you the basics of PredictionIO by configuring and setting a simple machine learning engine. This chapter also covers installation, architecture, and integration capabilities of the PredictionIO system.
Chapter 4, Product Recommendation Application using PredicitionIO and Salesforce App Cloud, teaches you how to build a simple product recommendation application using PredictionIO. This chapter covers how you can use Apex and Lightning Component and integrate SFDC with the PredictionIO Event Server and Engine.
Chapter 5, Salesforce Einstein Vision, helps you explore and learn the Salesforce Einstein Vision API. This chapter covers how you can build a Heroku node-based web application for image recognition using Einstein Vision offerings.
Chapter 6, Building Applications Using Einstein Vision and Salesforce Force.com Platform, teaches you how to use Einstein Vision API with the Salesforce Force.com platform. It also covers how you can integrate the Einstein Vision Services using Apex.
Chapter 7, Einstein for Analytics Cloud, covers the basics of the Analytics Cloud and Einstein Data Discovery offerings.
Chapter 8, Einstein and Salesforce IoT Cloud Platform, teaches you the basics of IoT Cloud offerings, Apache Kafka on Heroku add-on, Platform Events, and Identity Management on Salesforce for IoT devices.
Chapter 9, Measuring and Testing the Accuracy of Einstein, will cover how to use Salesforce reporting to measure the accuracy of the Einstein Predictions and Recommendations, and how to test and measure performance of a machine learning model.
This book assumes that the reader is familiar with programming, either as an open source developer or a Salesforce developer.
Basic knowledge of Apex
The backend language for Salesforce applications is called Apex. It is a strongly-typed object-oriented language, which is syntactically very similar to Java.
Basic knowledge of Scala
PredictionIO is a Scala application, and hence familiarity with Scala will help you understand the code better. It is strongly recommended that you should try all the code covered in the book on your own local machine and try deploying the code on the Heroku free instance.
Basic knowledge of frontend technologies such as JavaScript and HTML
Salesforce Lightning components use web technology such as JavaScript and HTML, and hence having a basic knowledge will help you a great deal.
Salesforce Developer instances and MAC OS X
You will need a Mac OS X to locally test the code covered in Chapter 3, Building Smarter Apps Using PredictionIO and Heroku and Chapter 4, Product Recommendation Application Using PredicitionIO and Salesforce App Cloud. Also, it requires you to have your own Salesforce and Heroku instances. To obtain a free Salesforce instance, sign up at https://developer.salesforce.com/signup, and to obtain a free Heroku account, sign up at https://signup.heroku.com/.
To connect Mac OS X to Heroku, download and install the Heroku CLI from https://devcenter.heroku.com/articles/heroku-cli.
This book is intended for experienced Salesforce developers and data scientists interested in exploring the breadth of Salesforce App Cloud offerings.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the
SUPPORT
tab at the top.
Click on
Code Downloads & Errata
.
Enter the name of the book in the
Search
box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on
Code Download
.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Learning-Salesforce-Einstein. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/LearningSalesforceEinstein_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
AI stands for Artificial Intelligence and it's been widely used in our daily life. Whether you are using Siri on your MacBook, Cortana on your Windows, playing Call of Duty, driving a smart car, or using movie recommendation services, all use Artificial Intelligence to a great extent to predict the outcome. Artificial Intelligence powers e-commerce Recommendation feeds, Facebook feeds, Fraud Detection in banking transactions, and many more use cases.
Salesforce CRM is one of the widely used CRMs today and there are tons of applications that are built on top of the Salesforce App Cloud platform used across various verticals, such as healthcare (Salesforce Health Cloud), finances (Financial Cloud and Financial Force ), insurance (Vlocity), and so on. Adding Artificial Intelligence to these types of applications will make the CRM and apps smarter. This book is an attempt to introduce developers on the Salesforce platform, the capabilities of the Salesforce Einstein (Artificial Intelligence for CRM), to bring Artificial Intelligence into the Salesforce apps, and also to introduce how Einstein can be used across marketing, sales, service, community, and various other Cloud offerings of Salesforce. We also cover PredictionIO, which is an open source machine learning server to build smarter applications.
Before we deep dive into Einstein offerings for developers and data scientists, this chapter covers the basics of Artificial Intelligence and key terminology in the world of Artificial Intelligence. Also, we will see how to use Google Prediction API's to build a simple demonstration of machine learning and Artificial Intelligence in conjunction with the Salesforce data to support the relevant theory.
In this chapter, we will cover the following topics:
Artificial Intelligence key terms
Programming languages used for machine learning
Practical machine learning with Google Prediction API and Salesforce
Artificial Intelligence is a computerized system that is designed to mimic how humans think, learn, process, and perceive information. In simple terms, it's about first understanding and then recreating the human mind.
There are some common terminologies that we need to understand before we proceed further.
As per Wikipedia:
"Machine learning provides computers with the ability to learn without being explicitly programmed"
Machine learning in general comprises three major steps:
We collect a lot of examples that specify the correct output for a given input.
Based on the input dataset, we apply algorithms to form a model or a mathematical function that can predict the outcome.
We pass the input to the mathematical function obtained in step 2 to obtain the necessary results. Consider the following diagram:
In this chapter, we will cover a simple experiment using Google's Prediction API with Salesforce data, and, in the later chapters, we will introduce you to the PredictionIO part of Einstein offerings from Salesforce, which is an open source Machine Learning Server that allows developers and data scientists to capture data via its Event server, build predictive models with algorithms, and then deploy it as a web service.
A neural network is a set of algorithms designed to recognize patterns. Neural networks are superficially based on how the brain works.
They consist of a set of nodes (similar to human brain neurons) arranged in multiple layers, with weighted interconnections between them. Each neuron combines a set of input values to produce an output value, which in turn is passed on to other neurons downstream. Artificial neural networks are used in Deep Learning.
In Deep Learning, the neural network has multiple layers. At the top layer, the network trains on a specific set of features and then sends that information to the next layer. The network takes that information, combines it with other features and passes it to the next layer, and so on.
Deep Learning has increased in popularity because it has proven to outperform other methodologies for machine learning. Due to the advancement of distributed computing resources and businesses generating an influx of image, text, and voice data, Deep Learning can deliver insights that weren't previously possible.
Consider the following diagram:
From an example from the U.S. government report, in an image recognition application, a first layer of units might combine the raw data of the image to recognize simple patterns in the image; a second layer of units might combine the results of the first layer to recognize patterns of patterns; a third layer might combine the results of the second layer, and so on. We train neural networks by feeding them lots of delicious big data to learn from.
Salesforce Einstein offers Predictive Vision Services (currently in Pilot) for training and solving image recognition use cases. We will discuss in detail how to use these services to bring the power of image recognition to the CRM apps.
Natural language processing (NLP) is the ability of computers to understand human language and speeches. A good example for this is Google Translator or a Google Voice Search. Modern day NLP systems use machine learning to detect patterns.
Cognitive computing involves self-learning systems that use data mining (big data), pattern recognition (machine learning), and natural language processing to mimic the way the human brain works. The difference between Artificial Intelligence and cognitive computing boils down to the idea that the former tells the user what course of action to take based on its analysis while the latter provides information to help the user decide. The goal of cognitive computing is to automatically solve IT problems without human intervention.
Humans have been finding patterns everywhere, ranging from astronomy to biology and physics. A pattern is a set of object/concept/phenomena where elements are like one another in certain aspects.
Statistical and structural patterns form the basis of machine learning.
Data mining is the process of finding patterns or correlations among dozens of fields in a relational database.
Data mining consists of the following five major elements:
ETL (Extraction ,Transformation and Loading ) of data from data warehouse
Storing and managing the data in a multidimensional database system
Providing data access to the Business Analysts and IT professionals
Use Application Software to analyze data
Using charts and dashboards to present the data
