Salesforce Summaries – Leverage Apex to Extract IoT Value from Your Data

Share this article...

SalesforceSummaries: a series delivering key insights from Salesforce YouTube videos, to save you time as you keep up to date with the latest technological changes within the Salesforce ecosystem.


In this presentation, you will learn more about how to leverage Apex to extract IoT value from your data.

Details: ‘Leverage Apex to Extract IoT Value from Your Data

**Presenter: **Michelle Szucs, Tim Peng

**Details: **20 minutes

Key Terms: IoT, Gateway

  1. @1.00 — The talk will focus most on how to get data from IoT devices into Salesforce. Salesforce IoT helps you get value from the data that you have already collected from IoT devices — it isn’t a platform.

  1. @2.10 — Salesforce takes in your data via Platform Events and from there, you can apply all the Salesforce features to your data. The 4 steps on how Salesforce IoT works is:
  2. @3.15 — A gateway device offers many advantages for connecting IoT devices. Heroku can act as a gateway. To connect with Salesforce, authentication is mandatory. If you set up a connected app via OAuth, you have many steps to take: you need a client secret, the token, callback url etc. The reason for these steps and the emphasis on security is to ensure that the right devices are connected, that the right apps are sending the right data and that the right people are making the right actions in your org. So, it is challenging at times to connect to Salesforce because some configuration and sometimes development is required. This level of complexity is not suitable for many small IoT devices because the authentication process would become overly burdensome for them. It takes a lot of bandwidth to perform the OAuth handshake. So, what is the solution?

You can leverage a proxy gateway or an IoT device platform, such as AWS, to handle the authentication for the IoT devices for you into Salesforce. In other words, the gateway is a connector (bridge) between Salesforce and the IoT devices.

  1. @10.15 — In this example, we will see how you can leverage Apex to convert a single gateway event into individual events.
  2. @10.30 — The high level steps to take are:
  3. @10.50 — All of the events that come into Salesforce come in via Platform Events. Any service that produces event driven data that needs to be input into Salesforce would leverage Platform Events. An event is defined as a change in state that is meaningful in a business process.
  4. @11.20 — Typically, IoT devices that will have its data feed into Salesforce via Platform Events do this by creating a JSON which is sent to an endpoint.
  5. @13.00 — To create a Platform Event trigger to handle any automation that needs to happen once the IoT data has come into Salesforce, you can just select ‘new trigger’ from the Platform Event page. Platform Event triggers run in ‘after’ execution context because they fire once data has been received.

The trigger parses the JSON that is sent to Salesforce via Platform Events. JSON2Apex can help to generate the Apex required to parse the JSON. More info on serializing and de-serializing Apex can be found here. To see how if this works, let’s POST the JSON that the IoT devices sends via Workbench.

We can see that the trigger has fired and that this has impacted the data:

There are so many use cases for leveraging IoT data with Salesforce.

Leave a Reply