Loading
Prepare for Email to Become the Default Login ExperienceRead More
Intermittent freezing when using using certain browser versionsRead More
Automate Your Business Processes with Salesforce Flow
Create Tasks After Waiting for a Platform Event Example

Create Tasks After Waiting for a Platform Event Example

Create a flow that automates your supply ordering by pausing your flow until a platform event confirms shipment, then create a follow-up installation task for the next day.

Required Editions

View supported editions.

The vendor that you buy supplies from has a platform event for you to subscribe to. The platform event, called Vendor Response, includes the order number, order status, and expected delivery date.

Note
Note This flow is part of a larger example. It gets launched by a process that starts when a Printer Status platform event message is received. For details about the process, see Sample Process: Printer Management.

The Order Printer Supplies flow starts when the Printer Management process launches it. The process populates the following variables in the flow.

  • {!assetId}—The asset's ID
  • {!assetOwner}—The asset's owner
  • {!inkManufacturer}—The manufacturer of the printer's ink
  • {!inkNeeded}—Whether the printer needs more ink
  • {!inkType}—Specific type of ink that the printer uses
  • {!paperNeeded}—Whether the printer needs more paper
  • {!paperSize}—Paper size that the printer uses
  • {!serialNumber}—The asset's serial number

First, the flow determines whether to order ink or paper. Based on the decision, it submits an order of ink or paper with the vendor by using an Apex action. Then it pauses until the vendor sends a platform event message that says the order has been shipped. When Salesforce receives the specified event message, the flow resumes and creates a task for the asset's owner to install the new supplies.

The entire flow created in this example

Decision Element

The decision includes two outcomes: Ink and Paper. The Ink outcome is true if the variable {!inkNeeded} is true. The Paper outcome is true if the variable {!paperNeeded} is true.

This Decision element determines whether ink needs to be ordered
This Decision element determines whether paper needs to be ordered

Apex Action Elements

The flow includes two Apex actions that submit a supply order with a vendor but provide different information to it based on whether the flow ran the Ink outcome or Paper outcome. All the variables used for input values (like {!serialNumber} and {!paperSize}) are set when a process launches the flow.

The first Apex action provides information about which ink to order.

The Apex class's inputs determine what supplies are ordered and for which printer.

The second Apex action provides information about which paper to order.

The Apex class's inputs determine what supplies are ordered and for what printer.

In both Apex actions, the action returns an order number. The flow stores that value in the {!orderNumber} variable to reference in the Wait element.

The Apex class's output variables, passed into a flow variable to be referenced later.

Wait Element

After the Apex action submits the supply order, the flow waits for confirmation that the order has been shipped. That confirmation is received through the Vendor Response platform event.

The flow pauses until Salesforce receives a Vendor Request event message with specific values. The order number must be the same as the order number that the Apex action provided. And the order status must be Shipped.

The event conditions subscribe the flow to a Vendor Response event only if it has a specific order number and order status.

When the correct event message is received and the flow resumes, the flow stores the event message's data in a record variable. That way, you can reference the expected delivery date to calculate when the supplies are scheduled to be installed.

Passing the event data to a Vendor Response record variable.

Create Records Element

When the flow resumes, it creates a task for the asset owner to install the new supplies.

Setting the task's fields with variables and flow resources.

For the task's field values, the flow uses these resources.

  • {!installDate}—A formula that calculates the day after the event's expected delivery date.
  • {!taskDescription}—A text template that gives more details about the installation.
  • {!assetOwner}—Provided by the process that launches the flow
  • {!assetId}—Provided by the process that launches the flow
Setting the task's fields with variables and flow resources.
 
Loading
Salesforce Help | Article