Mastering the Salesforce IoT Platform: A Step-by-Step Guide for Developers

Priti Patil
June 4, 2018
5 mins
Priyanka Baruah
August 22, 2024
5 minute read

An Introduction to Salesforce IOT

2018 has shown us the full potential of connected devices. Not only are people connected over the internet, but our gadgets, appliances and phones are all communicating with one another in some way. This opens up the space of IOT for deeper exploration and creates new opportunities in the space for all developers. Consumers have more power and data, and the convenience that smart devices bring is unmatched.

This is the new world of IOT everywhere. The Internet of Things has revolutionized the way that humans interact with technology, making their lives a lot easier. With sensors inside your car providing maintenance and service request updates, you can drive that much more safely. With smart refrigerators ordering groceries that need to be ordered, you’re living a life of convenience. The concept of IOT is expanding and brands are chiming in to create the best possible experiences for their customers.

Salesforce IOT

Salesforce, one of the foremost pioneers in cloud computing, has been excelling in the IoT space for quite some time now. They’re offering secure and scalable solutions that allow organizations to transform their business models with easy-to-use point and click configurations. From a developer’s standpoint, the ease of use has made the technology more accessible and setting up has never been simpler. Let’s take a deep dive into the world of Salesforce IoT.

Salesforce offers two main services under the IOT banner. The first one is a platform called IOT Scale, which is separate from their existing platform force.com. You can have the IOT edition org and set a unique point and click configuration model based on your business needs.

The second offering provided by Salesforce is the IOT explorer. This option is built on the Force.com platform and will be the focal point for this article ahead. It’s available to all developers as a part of their winter 18 release, and developers can get the latest updates from the website itself.

Power of Salesforce IoT Platform: Streamlining Workflow Automation

Salesforce gets data input from connected devices in the ecosystem and has predefined rules and logic to trigger an action. This input-output relationship makes it easier for developers to create IOT experiences that scale better.

The Salesforce IOT is a state machine, which operates as a nonlinear workflow engine. It manages the transition of objects and people from one defined state to another. That’s why it’s beneficial to developers who can create workflows that react to different events and contextual data in organic ways. Using this method. you don’t have to predefine a complete set of sequences to cover all possible combinations of events and connected data.

Here is a list of commonly used terms that are important to understand:

Salesforce commonly used terms

The Salesforce IOT Dataflow:

iot architecture

Steps to enable Salesforce IOT for your business

It’s a simple stepwise process to leverage the power of the Salesforce IOT platform for your business. Follow the steps mentioned below to unlock Salesforce’s complete potential.

A. Enable IOT Explorer

You can start by creating a new ‘Winter 18 Developer Edition’ org by quick searching for ‘IOT Explorer’ in setup. You need to switch to lightning experience if you haven’t already, as it works only in lightening experience mode.

    1. Create a new Winter ‘18 Developer Edition org
    2. Create an Account record: Universal Containers.
    3. Create a related Contact record: Dave Stanton.
    4. Add a custom field to the Asset object: (Add a checkbox custom field: Subscription)
    5. Create two Asset records: (Both records should lookup to the account and contact you previously created. One asset should have Subscription checked. The other asset should have Subscription unchecked.

B. Create Platform Events

This step is similar to that of custom object, and you can start creating platform events by quick searching in the setup option. We will use this to store our incoming event data.

  1. Create new deployed platform named Coffee Hopper.
  2. Add a Level custom field:
  3. Type: Number
  4. Field Label: Level
  5. Field Name: Level
  6. Length: 18
  7. Decimal Places: 0
  8. Add an Asset Id:
  9. Type: Text
  10. Field Label: Asset Id
  11. Field Name: Asset Id
  12. Required: true
  13. Length: 80
  14. C. Create Context‘Context’ is a combination of static data (stored in a custom object) and event data (stored in platform events). You can quick search for ‘Context’ in the setup option and create a new one.You can add platform event to context and include the key as well. The ‘key’ will be a unique field on the platform event, similar to a Product Id or a number.E.g. you can have ‘fridge’ details stored under ‘product’, which would be a static data point. This data point will have a product ID, a name, and some static data about the fridge manufacturer, quality, ratings, etc. You will also have a platform event where you can store incoming events. The platform event will have a unique field for product ID in-built. This common field represented on a custom object and a platform event will be the key for developing context.Remember – Field names need be the same on customer objects and events, but their data type should be the same to develop consistency in the system.
  15. Create a new Context:
  16. Name: Coffee Hopper ContextKey Type: StringSalesforce Object: AssetObject Key: Asset2.   Add a platform event to the context:Context: Coffee Hopper Context
  17. Platform Event: Coffee Hopper
  18. Key: Asset Id
  19. D. Build an Orchestration
  20. The process of building an orchestration is similar to that of using a process builder, where you can set conditions and rules to trigger actions. An orchestration is when you design the state machine, which subsequently combines the different possible states for a device (e.g. Normal, Warning, Fault, etc.).
  21. E.g. When we want to transition states based on the level of coffee available in a coffee hopper, we can set it to measure against percentage of levels. If the levels fall below 40%, the machine can state that the system is in ‘Warning state’. When it drops below 10%, the device can be made to be in ‘Fault state’. You can quick search for ‘Orchestration’ in the setup.
  22. Create a new Orchestration:
  23. Name: Coffee Hopper OrchestrationContext: Coffee Hopper ContextCreate additional states:2. Click Add State3. Again click Add State4. Rename your states by clicking on the text labels:
  24. Green: Normal
  25. Red: Fault
  26. Purple: Warning
  27. 5. Click the ellipsis for the Warning state:
  28. Click Move state up so that our states and colors are in a more logical sequence
  29. 6. Add transitions to your states:
  30. Normal
  31. When: Coffee_Hopper_e
  32. Condition: Coffee_Hopper__e.Level__c < 40
  33. Transition: Warning
  34. Warning
  35. When: Coffee_Hopper_e
  36. Condition: Coffee_Hopper__e.Level__c < 10
  37. Transition: Fault
  38. Fault
  39. When: Coffee_Hopper_e
  40. Condition: Coffee_Hopper__e.Level__c < 90
  41. Transition: Normal
  42. 7. Click Save
  43. 8. Click Activate.
  44. E. Testing your Orchestration
  45. To test the orchestration, you need to send a dummy platform event and check to see if the state transition occurs or not. In simpler terms, you need to see if the output of the system is desirable, given the right input. You can use the workbench rest explorer and send a post request with certain event data.
  46. Send event data:
  47. Click the POST method radio buttonUpdate the base url to be /services/data/v41.0/sobjects/Coffee_Hopper__eRequest Body: { “Asset_Id__c”: “abc123”, “Level__c”: 100 }2. Click the Execute button3. Look in the response information to ensure you see success: true4. Go back to your orchestration browser window.
  48. 5. Click on the Traffic tab within the orchestration page.
  49. 6. Confirm you have one instance in normal state
  50. F. Overview through Traffic view
  51. Traffic view shows you a pictorial representation of all your states, displaying them in different colors and states. Salesforce automatically shows you the traffic view, and it’s a handy tool when understanding the flow of information.
  52. Keep experimenting with this amazing piece of software and making IOT a reality for your business!

Your vision, our expertise—let’s make it happen.