How to Create a Platform Event and Modify the Object



Platform Event

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.

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 the steps above, you have a platform event object that looks like this.

Create a Key Field on the Asset Object

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 UniqueDo 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.

This blog is very useful to learn about platform event.