There are a few articles about how to create platform events in Salesforce, but most of them have lots of fluff and unnecessary details. So here’s a concise version.

We’ll use the Nonprofit Success Pack (NPSP) example, in which a household account is created when a contact is created. For household accounts, there’s a Lookup(Contact) field called “Primary Contact”, which is always set when the household account is created.

The goal is we want to know when the household account is actually created so we can perform some followup actions.

Step 1: Create a Platform Event

  1. Create a new platform event by navigating to Setup > Platform Events > New Platform Event
  2. This is like creating an object, but for an event. So let’s use the label “Household Created”
  3. Add some text fields to the event, such as “Account Id,” Contact Id”

Step 2: Setup the Publisher

  1. This step publishes the event to the platform when the account is created
  2. Create a record-triggered flow on the account object with some entry conditions, including the proper RecordType Id and the Primary Contact is set
  3. Add a Create Records element, using the object (i.e. event) “Household Created”
  4. Set
    1. Account Id = Triggered Account.Account Id
    2. Contact Id = Triggered Account.Primary Contact

Step 3: Setup the Subscriber

  1. This step observes the platform event and takes appropriate actions
  2. Create a platform event – triggered flow using the “Household Created” event
  3. You now have access to the fields on the “Household Created” event, which are
    1. Account Id = the newly created household account
    2. Contact Id = the primary contact that initiated the creation of the household account

Step 4: Profit!
Just like the underwear gnomes 🙂

The takeaway
In 3-4 simple steps, you have a powerful mechanism available to manage and leverage platform events.

Category:
Salesforce