Enable Salesforce IoT and Create a Context and Dummy Record
- Enable Salesforce IoT.
- Explain what a context is.
- Create a context for a simple use case.
Enable Salesforce IoT
Before you start creating contexts and orchestrations, you first enable Salesforce IoT. Here’s how you do it.
- From Setup, enter IoT in the Quick Find box, then select Get Started.
In the Enable Salesforce IoT box,
After you enable, your screen looks like this.
What Is a Context?
A context specifies the sources of data that an orchestration can access: one or more platform events and, optionally, a Salesforce object. Each platform event and optional Salesforce object must have a key field whose values are used by each orchestration instance to access the relevant event messages and object record.
For example, in our Flying Fridge use case, the serial_no key field on our platform event enables an incoming event message to trigger an orchestration instance to run for a specific refrigerator. That orchestration instance matches that key value against the Fridge_Serial_Number key field on the Asset object to read the corresponding asset record for that same refrigerator. Notice that the key field names don’t need to match; only the key values and data types must match.
Create a Context
- From Setup, enter IoT in the Quick Find box, then select Contexts.
- Click New Context.
- For Context Name, enter Flying Fridge Context.
- For Description, enter All the refrigerator events and object data for fridge orchestrations. This description is displayed in the context detail page.
- Click Create.
This is what your context looks like.
- In the context, click Add Event Data.
- From the available platform events, select Flying Fridge Event. Click Next.
- In Choose the Key, select serial_no__c. Click Apply.
- Now click Add Reference Data.
- Under available objects, select Asset. Click Next.
- In Choose the Key, select FridgeSerialNumber__c. Click Apply.
- Click Save, then Activate.
- Click Done to exit.
Your context now looks like this.
Your context is ready to use in an orchestration. We have one last step before we start building our orchestration.
Create Some Data for the Flying Fridge Use Case
Before we go any further with building out our use case, we make sure we have the data we require to test out our use case once all the pieces are put together. In your Trailhead Playground or Developer Edition org, you first create a new field and a new asset record.
- In Setup, click Object Manager.
- In Object Manager, select Asset.
- In Asset, select Fields & Relationships.
- On the Fields & Relationships page, click New.
- Select Number, and click Next.
- For Field Label, enter Max High Temp.
- For Length, enter 18.
- For Field Name, enter Max_High_Temp.
- Click Next.
- Keep the defaults for field-level security, and click Next.
- For Add to page layouts, click Save.
Under Fields & Relationships, you now see the Max High Temp field.
- Click to open the App Launcher, and under All Items, click Assets.
- Click New.
- In New Asset, enter an Asset Name, for example, Flying Fridge Mini.
- Click Account, and select New Account.
- For the Account Name, enter Awesome Airline, and click Save.
- Click Contact, and select New Contact.
- For Last Name, enter Earhart.
- For Account Name, select Awesome Airline.
- Click Save.
- For Fridge Serial Number, enter 1001.
- For Max High Temp, enter 50.
- Click Save.
Now, you have an asset record that looks like this.
Now we have all the pieces in place to move forward with building and testing our orchestration. When we do this, we see how easy it is to create and iterate IoT solutions in Salesforce IoT.
Stay the course and keep exploring.