Connecting Salesforce to Medium One

This tutorial connects your Medium One account with your Salesforce account. Once connected, whenever a case is created in Salesforce, a ticket is sent to Medium One. Device data is gathered and posted back to the Salesforce’s case automatically.

In this tutorial, you will understand how data is transferred between Medium One and Salesforce. You will create a ‘case’ in the Salesforce environment and view this event via datastream in Medium One. Additionally, you will use a Medium One workflow to add a comment to the case. 

Prerequisites:

Step 1: Log into your Medium One account

For this tutorial, you’ll need to have a Medium One account. If you don’t already have one, sign up here.

 

Step 2: Create an API Key and API Basic User

Once logged into your Medium One account, create an API Key by going to Setup -> Manage API Keys. Click on “Add New API Key” and Save. Make sure the ‘Enabled’ box is checked. Note the API Key, you will need it in Step 4.

Next, we’re going to create an API Basic User. Go to Setup -> Manage Users. Click  on “Add New User”. Type in a username and password then save. Note these credentials, you will need it in Step 4.

 

Step 3: Create a Salesforce.com free developer account

Now, sign up for a free developer salesforce account at: https://developer.salesforce.com/signup

Enter all required data and click “Sign me up” to create account.

Note: You will receive a welcome ‘Your Developer Edition Login Information’ email from salesforcedevs.com stating your user name and asking you to set your password. Follow through these instructions.

Once you have created your developer account, you will need to configure your account to connect it to the Medium One environment; this is shown in the following step.

Step 4: Setup and Configure Salesforce.com

Enable Apex Permissions in Salesforce

a.  Salesforce Viewing Mode (Lightning or Classic)

If you see a salesforce page similar to the following, you are in the new Salesforce Lightning Experience mode. Switch to Salesforce Classic mode by selecting the person icon in the upper right and then click on Switch to Salesforce Classic.

If you are already in Salesforce Classic mode, go to (b).

You will be switched to Classic Mode and see the following view.  Click on “Setup” in the top righthand corner.

b.  System Administrator Mode

Setup will open up the Administer page.  Look for System Administrator under Recent Items and click on it.

If you don’t find it, go to “Administer” -> “Manage Users” -> “Profile” in the sidebar.

Under Profiles, you should find System Administrator.  Click on it.

The ‘System Administrator’ profile page will appear as shown below.

Now scroll down and check that the Author Apex permission is enabled.

Add Medium One to Approved Sites

Click on “Setup” in the upper righthand corner on Salesforce.com.  Go to the quick find box on the left-hand side, type in “remote.” Under “Security Settings”, click on “Remote Site Settings.”

You will see the Remote Site page.  To add Medium One as a new remote site, click on New Remote Site.

Add remote site URL to “https://api-sandbox.mediumone.com

Click Save.

Create Apex Classes

From the Salesforce Developer Force Homepage you should see your name next to the Setup button on the top right hand corner. Click on your name, then click on Developer Console underneath it.

A new window should open. Click on File → New → Apex Class. Name the class “M1”.

Replace the existing code by copying and pasting the following into the window, replacing <DEVICE_PASSWORD> with the API basic user’s password, <API_KEY> with your API key from the email described in Step 1.

Go to File→ Save.

Now, you need to create the trigger. Go to File→ new → Apex Trigger.

Name the class “m1_trigger”. Choose the sObject to be ‘Case’ and Submit.

Copy and paste the following into the window:

Click File ->Save.

You may now close the Force.com Developer Console window.

Now, whenever you create a new case, it will send case details to your Medium One account.

You have successfully created your test classes, and can deploy your code to production. For information on moving code from sandbox to production, click here.

Notes:

This APEX code snippet sends salesforce.com under the datastream called ‘salesforce’. If you would like to connect your production salesforce.com account (non developer), you’ll need to create APEX test code.  Refer to the Appendix A: for sample test code.

Step 4: Link Salesforce.com to Medium One

In Medium One, go to “Setup”  -> “External APIs.” Click “Add New Service Key”.

Select ‘salesforce’ from the drop down menu; then click “Save and Activate”.

If this is your first time logging to Salesforce account, you will need to allow access for Salesforce. Click ‘Allow”.

Lastly, a window will open up saying ‘Authentication successful. You may close this page.’

Now, you can post to and edit cases from M1 workflows.

Create salesforce stream on your Medium One project

In Salesforce.com, the created APEX code snippet sends salesforce.com under the datastream called ‘salesforce’. Now, we need to create and link this ‘salesforce’ datastream in Medium One.

In Medium One,  go to “Config” -> “Data Streams”, then click on 

In Create New Data Stream, enter a new stream’s name to be ‘salesforce’; then click “Save Data Stream”.

Now, the ‘salesforce’ datastream is linked to collect all events between saleforce.com and Medium One.

Check Point

You can quickly check that your new environment is generated correctly by creating a case, and seeing its data stream created in Medium One environment.

In home page of Salesforce.com, click on “+” and then on “Cases”.

Create a new case by clicking on “New“.

Fill all required information (Account Name, Status, Case Origin, Subject, and Description) to “New Case” ; then click “Save”.

Note: If this is a new ‘Account Name’ that is not linked in your account profiles, you will quickly need to create it by clicking on magnifying glass, then on “New’ and entering all necessary info to the Account page; then click “Save”

By clicking “Save” on Creating a new case, we created a new event, which was sent to Medium One. Now, we can easily check if we have received this event by opening the Data Viewer and checking the content of ‘salesforce’ datastream.

In Medium One, go to “Data Viewer” -> “Data Streams”. Click “View” on newly created ‘salesforce’ datastream.

If the creation of case in saleforce.com was successful, you will see the following log file in the data stream viewer:

You can expand the device’s log file from this event by clicking on ‘+’ sign:

NOTE: If no event appears, don’t continue and go back and make sure you follow all steps correctly.

Step 5: Create a Salesforce workflow

In this section we will create a workflow that will trigger when a salesforce.com case is created.  This workflow will leave a comment on the Salesforce case.

Create a new workflow and name it “Salesforce”; then click and drag salesforce tag Id” as your trigger. This will run the workflow every time a new case is created through Salesforce. Next, under ‘Foundation’, drag Base Python onto the canvas and connect the modules. Your workflow should look like this:

Double click on Base Python , and replace the existing script with the following code:

Then click “Save and Activate”. This workflow adds a comment “Comment from Medium One” to every case created on your Salesforce account.

Check point

Now, let’s create a new salesforce case and test the created workflows.

In this tutorial, we created a new case with Subject: Device not working in salesforce.com.

Once we click on “Save”, this case was created. Click on Feed tab and you will see acknowledgement of the case creation. You can read the comment that the case was created.

Refresh the salesforce page and see the event on salesforce.com. In the section ‘All Updates for this case’, you can view the comment from Medium One.

Congratulations! You just connected salesforce.com to the Medium One and automatically populated the case with a comment.

WHAT’S NEXT?

Now that you know how to automatically populate a case with a comment, the possibilities are endless. From commenting with device data or retrieving user information, the rest is up to your imagination!

Appendix A: Add Apex Test classes

Salesforce requires that for deployment to Production organizations, at least 75% of the Apex code must be covered by test cases. If you plan on moving off of a Developer organization, you must add the following test interfaces and tests.

The reason for creating these test classes is that you may not have a real HTTP callout in a test, so you must create mock HTTP Callout responses to demonstrate how the data should respond given the input.

In Force.com Developer Console, click on File→ New -> Apex Class, and name the class “TestM1SucessfulSendEvent.” Copy and paste the following code in, replacing <YOUR_ENVIRONMENT> with the URL you placed in Remote Site Settings in step 3.

Click Save.  Click File→ New -> Apex Class, and name the class “TestM1SucessfulLogin.” Copy and paste the following:

Click Save.

Create the last class and name it “M1Test.” Paste the following:

Now you have successfully created your test classes, and can deploy your code to production. For information on moving code from sandbox to production, click here.

vivian@mediumone.com'

Author: Vivian Kha