Salesforce Einstein Intent: A Quick Overview

Salesforce Einstein Intent: A Quick Overview

Hi All, As Dreamforce is over and there are lots of new things in the market. but Einstein is on top of that. In my previous post I have already shared about Einstein Vision to predict the image. Today we will cover the basic of Einstein Intent A search Prediction.

You can use Einstein Intent to make a case prediction and route the case to different user  so that case can be solved much faster with less human intervention.

3342fe7-intent_and_sentiment_flow.png

The process is same as we have done for Einstein Vision. First if you don’t have API key or access token then you need to create one. You can follow the same steps as previous post.
After that we first need to create sample Dataset. In this step, you define the labels that you want the model to output when text is sent into the model for prediction. Then you gather text data for each of those labels, and that text is used to create a model.

You can use sample CSV which I have used or can create your own as well.

Then you need to train that dataset. You can also make request to check status of training. and once training is completed you can make your first prediction.

The text which I used for prediction is “Why my shipping address is changed.” And the response which I get is

Prediction Result.png

 

Its related to Billing and it is Correct. You can create large dataset to make these prediction more accurate. And can play with it yourself.

Let me know what you like most about Einstein in comments. If you want to add something share with me in comments section.

Happy Programming 🙂

Advertisements

Salesforce Einstein Vision: Quick Overview

Salesforce Einstein Vision: Quick Overview

Einstein Vision is part of the Einstein Platform Services technologies, and you can use it to AI-enable your apps. Leverage pre-trained classifiers, or train your own custom classifiers to solve a vast array of specialized image-recognition use cases. Developers can bring the power of image recognition to CRM and third-party applications so that end users across sales, service, and marketing can discover new insights about their customers and predict outcomes that lead to smarter decisions.

Einstein Vision includes these APIs:

  • Einstein Image Classification—Enables developers to train deep learning models to recognize and classify images at scale.
  • Einstein Object Detection (Pilot)—Enables developers to train models to recognize and count multiple distinct objects within an image, providing granular details like the size and location of each object.

0089e22-vision_terms_graphic.png

Today we will cover the Einstein Image Classification . As we have a very good Apex wrapper provided by Salesforce dev team here. Which you can use to make all request of Einstein while it handle all the heavy work in background for you.

But if you don’t want to install a full library to test these requests then I will share quick code sample which you can use to create your own request.

Before we start first you need to make sure that you have completed all prerequisite steps. You need a valid Einstein token to call API and few base classes to make request.

After all this setup our org is ready to make our first prediction. For our demo purpose we will use Bike vs Car model. Here I have commented Token Id, Dataset Id and Model Id you can enter your related Id there.

First  to make a request we need the access token, Here we take help of our base classes which we have included. To get the access token we will use JWT access token helper.

 

Then we need to make our Dataset: A data set is a folder which contains the images. Here we pass the data in multipart/form-data format.

Dataset can be created Asyn or syn. In our example we are creating Asynchronously.

Next we will train our dataset to identify the images. You will get Dataset ID from previous request.

this command train the Dataset and create a Model. Model creation process takes time based on number of images which you have provided. In our example number of picture is less so it will complete early.

You can also check the status

Once the Dataset is trained we are ready to make our first prediction.

For prediction we will use this image

18

 

And the response we get is

Screenshot_2.png

 

So we get Almost 100% for this image. You can make your own Dataset and can play with them.

Let me know what you like most about Einstein in comments. If you want to add something share with me in comments section.

Happy Programming 🙂

Lightning: A Simple Multi Select Component

 

 

As we all know Lightning is on boom now. With every release we get new feature and functionality on Lightning. Many of us are just realized how much it is important to learn lightning so now I will share some small code sample related to Lightning in upcoming using them you can get a quick start your Lightning study. i also recommend you to check my previous post to get the basic Idea.

Today I will share a simple multi select component where we will pass data between two components.

MSPL.gif

Lightning Component

Controller JS


As from code you can easily get the idea that I have used component.get and have passed the attribute value to get the selected value and add/ remove the value from list. You can find the complete code here. Play with it and let me know if you face any issue.

 

Happy programming 🙂

Connect Salesforce with Authorize.Net

Connect Salesforce with Authorize.Net

Hi All, We all know about authorize.net. Its the most common payment gateway used to make payment transaction from Website. We can also use it with Salesforce to setup payment gateway where our users can make a purchase and do payments as well.

Its very easy to connect Salesforce with Authorize.net. In this post we will use Sandbox account to make transaction but you can follow same steps for live transactions.

  • First Sign up for a Sandbox account here. Screenshot_2.pngNow you will get Login Id and Transaction Key. Store them in some place so that we can use them later.

Screenshot_1

  •  Now there are various method from which we can make a payment, Authorize a payment, Charge a card later and void the transaction. In case of Production URl we need to change the base URl.
  • Also make sure you add the base URL in remote site setting.

Screenshot_3.png


public with sharing class AuthorizePayment {

private string APIkey = '********';
private string transKey = '************';
private string Amt = '5';
private string cardNum = '5424000000000015';
private string expdate = '1220';
private string cvvCode = '999';

//Method to make payment and charge the card
public void makePayment(){
//Getting access token from Paypal
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{"createTransactionRequest":{"merchantAuthentication":{"name":"'+APIkey+'","transactionKey":"'+transKey+'"},'
+'"refId":"123456","transactionRequest":{"transactionType":"authCaptureTransaction","amount":"'+Amt+'","payment":{"creditCard":'
+'{"cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'","cardCode":"'+cvvCode+'"}},"lineItems":{"lineItem":{"itemId":"1","name":"vase",'
+'"description":"Cannes logo","quantity":"18","unitPrice":"45.00"}},"tax":{"amount":"4.26","name":"level2 tax name","description":"level2 tax"},'
+'"duty":{"amount":"8.55","name":"duty name","description":"duty description"},"shipping":{"amount":"4.26","name":"level2 tax name",'+
'"description":"level2 tax"},"poNumber":"456654","customer":{"id":"99999456654"},"billTo":{"firstName":"Ellen","lastName":"Johnson",'+
'"company":"Souveniropolis","address":"14 Main Street","city":"Pecan Springs","state":"TX","zip":"44628","country":"USA"},"shipTo":'+
'{"firstName":"China","lastName":"Bayles","company":"Thyme for Tea","address":"12 Main Street","city":"Pecan Springs","state":"TX","zip":"44628",'+
'"country":"USA"},"customerIP":"192.168.1.1","transactionSettings":{"setting":{"settingName":"testRequest","settingValue":"false"}},'+
'"userFields":{"userField":[{"name":"MerchantDefinedFieldName1","value":"MerchantDefinedFieldValue1"},{"name":"favorite_color","value":"blue"}]}}}}';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//Method to authorize the card to make the payment later
public void authorizecard(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" }, '+
'"refId": "123456", "transactionRequest": { "transactionType": "authOnlyTransaction", "amount": "'+Amt+'", "payment": { "creditCard": '+
'{ "cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'","cardCode":"'+cvvCode+'" } }, "lineItems": { "lineItem": { "itemId": "1", '+
'"name": "vase", "description": "Cannes logo", "quantity": "18", "unitPrice": "45.00" } }, "tax": { "amount": "4.26", "name": "level2 tax name",'+
'"description": "level2 tax" }, "duty": { "amount": "8.55", "name": "duty name", "description": "duty description" }, "shipping": '+
'{ "amount": "4.26", "name": "level2 tax name", "description": "level2 tax" }, "poNumber": "456654", "customer": { "id": "99999456654" },'+
' "billTo": { "firstName": "Ellen", "lastName": "Johnson", "company": "Souveniropolis", "address": "14 Main Street", "city": "Pecan Springs",'+
' "state": "TX", "zip": "44628", "country": "USA" }, "shipTo": { "firstName": "China", "lastName": "Bayles", "company": "Thyme for Tea", '+
'"address": "12 Main Street", "city": "Pecan Springs", "state": "TX", "zip": "44628", "country": "USA" }, "customerIP": "192.168.1.1", '+
'"transactionSettings": { "setting": { "settingName": "testRequest", "settingValue": "false" } }, "userFields": { "userField": [ '+
'{ "name": "MerchantDefinedFieldName1", "value": "MerchantDefinedFieldValue1" }, { "name": "favorite_color", "value": "blue" } ] } } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//Method for refund the settled payment
public void refundPay(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" },'+
' "refId": "123456", "transactionRequest": { "transactionType": "refundTransaction", "amount": "5.00", "payment": { "creditCard": '+
'{ "cardNumber":"'+cardNum+'","expirationDate":"'+expdate+'" } }, "refTransId": "60024747323" } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();
Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));

}

//method for cancel the unseattled payment
public void voidPay(){
HttpRequest req1 = new HttpRequest();
req1.setMethod('POST');
req1.setEndpoint('https://apitest.authorize.net/xml/v1/request.api');
req1.setHeader('content-type', 'application/json');
/*
Production URL: https://api.authorize.net/xml/v1/request.api

XSD URL: https://api.authorize.net/xml/v1/schema/AnetApiSchema.xsd
*/

string messageBody1 ='{ "createTransactionRequest": { "merchantAuthentication": { "name":"'+APIkey+'","transactionKey":"'+transKey+'" },'+
'"refId": "123456", "transactionRequest": { "transactionType": "voidTransaction", "refTransId": "60024747323" } } }';

req1.setHeader('Content-length', String.valueOf(messageBody1.length()));
req1.setBody(messageBody1);

req1.setTimeout(60*1000);
Http h1 = new Http();
String resp1;
HttpResponse res1 = h1.send(req1);
resp1 = res1.getBody();Map<String,object> responseMap =(Map<String,object>)JSON.deserializeUntyped(res1.getBody().substring(1,res1.getBody().length())) ;
for(string keyStr : responseMap.keyset())
system.debug(keyStr+'-----------Response------------------>>>>'+responseMap.get(keyStr));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Confirm, resp1));
}

}

  • From the transaction response you will get the transId which you can n cancellation and other processes. You can read more about them in detail from here.

So now you can setup a payment gateway in your force.com site or for internal user. If you like this post or want to add something let me know in comments section.

Happy Programming 🙂

Salesforce Summer 17: Cool Seagulls in Summer

Hi everyone, we all know Salesforce release 3 updates for its system in a year.  Now Salesforce recently launched Summer 17. Summer is hot and in Rajasthan it’s very hot.  So here are few hot and exciting updates for everyone.

Summer_17_Release_Logo

  1. Use Advanced PDF to Render Visualforce Pages as PDF Files (Pilot)

Advanced PDF renders Visualforce pages as PDF files with broader support for modern HTML standards, such as CSS3, JavaScript, and HTML5. This change applies to both Lightning Experience and Salesforce Classic.

To use Advanced PDF, set renderAs=”advanced_pdf” in the tag of a Visualforce page with API version 40.0 or later. This process is similar to the existing process for rendering a Visualforce page as a standard PDF file.

PDF pages rendered with Advanced PDF are subject to the same limitations as legacy PDF pages, including the maximum page size and limited number of fetched resources. Advanced PDF pages also time out after rendering for 2 minutes, which includes asynchronous processing time.

  1. Roll Back Changes in Your Org When Remote JavaScript Methods Throw Exceptions

When a JavaScript method in an Apex class calling a remote action throws an exception, the action isn’t completed. Previously, when a method threw an exception, the action was completed.

For example, when you created an Apex class that used a remote action to add an account to your org and that method threw an exception, the account was added. Now, the account isn’t added. With this enhancement, JavaScript remoting methods that throw exceptions no longer cause changes in your org. This change applies to both Lightning Experience and Salesforce Classic.

  1. Cache Operations Supported in Visualforce Controllers

Cache operations made using the put and remove methods in the Cache Namespace are now supported in constructors and getter methods of Visualforce controllers.

  1. New Option for Parallel Testing on the isTest() Annotation

Use the @isTest(isParallel=true) annotation to indicate test classes that can be run in parallel and aren’t restricted by the default limits on the number of concurrent tests. This makes the execution of test classes more efficient, because more tests can be run in parallel.

  1. Deploy Changes Now Trigger Recompile of All Apex Code

All of an org’s Apex code is now automatically recompiled before completing a metadata deploy, a package install, or a package upgrade.

Previously, a deploy, install, or upgrade left the org with invalidated code, which sometimes caused recompilation errors when many Apex transactions occurred. This change in behavior improves performance following metadata deploys and package updates.

  1. Disable Access to Non-global Apex Controller Methods in Managed Packages (Critical Update)

This critical update corrects access controls on Apex controller methods in managed packages. When this update is enabled, only methods marked with the global access modifier are accessible by Lightning components from outside the package namespace. These access controls prevent you from using unsupported API methods that the package author didn’t intend for global access.

Prior to this update, non-global methods (that is, Apex controller methods that weren’t marked with the global access modifier) could be accessed by Lightning components outside of the package namespace.

  1. Metadata Access in Apex

If you’re an ISV creating apps that use custom metadata components, you can now access     metadata using Apex. This change applies to both Lightning Experience and Salesforce Classic.

During or after an install (or upgrade), your app can create or update metadata to let users configure your app. Use the new Metadata namespace for accessing metadata in Apex code. The Metadata namespace contains classes that represent metadata types and components as well as classes that let you retrieve or deploy metadata components in the subscriber org.

  1.   Salesforce Integrations: Taking Salesforce to the Next Level

Now you can connect Salesforce with Skype for Business , Gmail, Google Calendar and Microsoft Office 365. They are generally available in both Lightning and Salesforce classic. Nut some of them are only available in Lightning.

  1. Einstein Vision Is Now Generally Available

Sign up for Einstein Vision to receive 1,000 free predictions per calendar month. If you need more predictions, you can purchase them.

Getting an Einstein Platform account is the first step to accessing the API. Use the sign-up page to get an account. You can get an account in two ways.

  • Heroku—When you provision the Einstein Vision add-on, an Einstein Platform account is created for you.
  • Salesforce—Log in with your Salesforce credentials and create an account.

After you create an account, you download your private key file. Use this file to create an access token.

You can also try your hand on a Trailhead project to understand it better.

  1. Removed LockerService Restriction on instanceof in JavaScript

    Previously, Salesforce advised against using theinstanceof operator in JavaScript code when LockerService is activated. This restriction has been removed, except when checking arrays.

There are many more other update related to Lightning and Einstein. As I am also reading them in more details so I might make another post for them in depth. This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release.

Sign up now for a pre release org.

You can read release notes here. Let me know if I missed something here or if you want to add something then let me know in comments section.