Start tracking your progress
Trailhead Home
Trailhead Home

Create a Platform Event and Modify the Asset Object

Learning Objectives

After completing this unit, you’ll be able to:
  • Describe what a platform event is.
  • Explain how platform events work with Salesforce IoT.
  • Create a platform event for a simple use case.
  • Create a key field on the platform event that matches each event message with a running instance of an orchestration.
  • Create a key field on the Asset object that matches each record with an orchestration instance.

What Is a Platform Event?

You’ve just taken off and are enjoying a beautiful clear day. But wait. What’s that off in the distance? And there’s another one. And another. Those are streaming events flying past you across the airwaves. In this unit, we talk about how those events come into Salesforce IoT through platform event messages.

Even if you have already earned your Platform Events Basics badge, here’s a little reminder of what platform events are.

Just like custom objects, you define platform events in Salesforce. You create a platform event definition by giving it a name and adding custom fields. Here is a sample definition of custom fields we add to a platform event for the payload coming from the Flying Fridge refrigerators.
Field Label Field API Name Data Type
serial_no serial_no__c Text(255)
door_open door_open__c Checkbox
temperature temperature__c Number(18.0)

Platform Events and Custom Objects

A platform event is a special kind of Salesforce entity, similar in many ways to a custom object. An event message is an instance of a platform event, similar to how a record is an instance of a custom object. Unlike with custom objects, you can’t view event records in the Salesforce user interface, or update or delete them.

You can set read and create permissions for platform events. You grant permissions to users in profiles or in permission sets.

How Platform Events Work with Salesforce IoT

Create a platform event to send streaming event data to your orchestration to trigger actions within Salesforce. You can set up the orchestration to enrich the data from the platform event fields with historical or contextual data from a Salesforce object, such as customer name, number of previous cases, manufacturing details, and so on.

Follow along as we create a platform event for our Flying Fridge use case.

Create a Platform Event

You create platform events from the Setup menu. Let’s create a platform event definition that holds the event data from the Flying Fridge refrigerators.

Define a platform event named Fridge Event.

  1. From Setup, enter Platform Events in the Quick Find box, then select Platform Events.
  2. On the Platform Events page, click New Platform Event.
  3. For Label, enter Flying Fridge Event.
  4. For Plural Label, enter Flying Fridge Events.
  5. For Description, enter Flying Fridge events received from commercial refrigerators.
  6. Click Save.
  7. In the Custom Fields & Relationships related list, click New.
  8. Select Text, and click Next.
  9. For Field Label/Name, enter serial_no.
    Later, we use this serial_no field as the key for matching event messages with orchestration instances.
  10. For Length, enter 255.
  11. Click Required.
    The platform event key field must be a required field.
  12. Keep the defaults for the other fields and leave the Description field empty. Click Save.
  13. Follow steps 7, 8, and 9 to add the next two fields:
    Field Label/Name Field Type
    door_open Checkbox
    temperature Number (Length=18)
    After following these steps, you have a platform event object that looks like this.

    Fridge Event platform event with the following custom fields: door_open, serial_no, and temperature

Create a Key Field on the Asset Object

One of the really cool features of Salesforce IoT is that orchestrations can access data from a Salesforce object. To do that, we add the object to the context, and we create a key field on the object that matches each record to an orchestration instance. For each orchestration instance, the record’s key value must also match the key values of event messages used by the orchestration instance. But the key field names can differ among the platform events and the object.

If that seems complicated and you’re not sure what orchestrations or contexts are, don’t worry. We go over contexts and orchestrations in the following units. What’s important to understand now is that we need to create a key field on the Asset object that we use in Salesforce IoT to access the reference and historical data for each asset and combine it with the incoming event data for the asset.

Follow along as we do this for our Flying Fridge use case.

Add a custom field to the Asset object that we use as the key.

  1. In Setup, click Object Manager.
  2. In Object Manager, select Asset.
  3. In Asset, select Fields & Relationships.
  4. On the Fields & Relationships page, click New.
  5. Select Text, and click Next.
  6. For Field Label, enter Fridge Serial Number.
  7. For Length, enter 255.
  8. For Field Name, enter Fridge_Serial_Number.
  9. Select Unique. Do not allow duplicate values.
  10. Click Next.
  11. Keep the defaults for field-level security, and click Next.
  12. For Add to page layouts, click Save.
    Under Fields & Relationships, you now see the Fridge Serial Number field.

     Fields and Relationships page with the Fridge Serial Number field

    In the next unit, we hit our cruising altitude as we learn about and create a context for our Flying Fridge use case.