Platform Events

CloudFiles Event Handler Flow Template

Introduction

To use CloudFiles Platform Events, It is important to correctly setup your platform event triggered flow that can intercept the CloudFiles Event and get the event details using the very useful Get Event Details flow action. This article explains the process of setting up this flow. Read this article carefully to enjoy the benefits of the CloudFiles Platform Event in Salesforce.

In this article, we provide a small summary of how to set up this flow before giving a comprehensive step by step guide with screenshots.

Summary

We will follow 3 steps to setup the CloudFiles Event Handler.

  1. Create an empty Platform event triggered flow with the CloudFiles Event as the trigger.
  2. Create a decision element to filter flow executions based on event & object types.
  3. Use the output of the Get Event Details flow action to process the event and setup specific custom use-cases.

Here is how our final flow looks. Follow the steps in the next section with screenshots for detailed information.

Document image


Step By Step Guide

1 - Create a Platform Event Triggered Flow

Salesforce provides many types of flows. E.g. record triggered flows, auto-launched flows etc... Platform Event Triggered flows are another type of flow that can be set up using the Salesforce flow builder. These flows are special, and can be triggered by external applications such as CloudFiles.

To create a platform event triggered flow, go to the Salesforce flow builder, create a new flow and select the type as Platform Event - Triggered Flow as shown in the screenshot below.

Salesforce Platform Event based flow
Salesforce Platform Event based flow


Once the flow is created, you will be asked to choose a Platform Event which would trigger this flow. Select the "CloudFiles Event" from the list of events as shown below -

Document image


With this, you now have empty Platform event flow set to trigger whenever a CLoudFiles Event happens. In the next section, we will learn how to filter based on the event type and other parameters. This must be done before moving the further step of making a callout to receive the event details.

2 - Add a decision element on the CloudFiles Event Object

Now that we have a Platform event flow setup, it will trigger on every CloudFiles event. It is necessary to filter based on event type to receive the event details correctly. It is also important to filter based on the object types where you need this flow to trigger.

These decisions can be set up using two important fields provided by the CloudFiles Event Object itself. This is the shown in the image below. The CloudFiles event Object is the 'Record' on which the Platform event triggered flow, triggers. This record can have very limited information due to certain Salesforce restrictions. For this reason, CloudFiles Event Object only carries 2 important fields.

  1. Type - This refers to the type of event. E.g. file-uploaded, salesforce-file-attached, etc... A full list is provided in our article for All Event Types.
  2. Object Type - This refers to the API name of the Salesforce record Type on which you want to intercept these events. E.g. to intercept file uploads into the salesforce files component on the Account records, we would use Type = salesforce-file-attached, and the Object Type = Account.

This object DOES NOT carry any actual details related to the event. Refer to next step for this. There are other fields as well but they are not meant for your use. For a full reference refer the article on CloudFiles Event Object.

It is important to note that the actual details of the event are not present in the CloudFiles Event object. The Get Event Details flow action is used to get the actual event details. Refer to the next step for more info on this.

Document image


At this point, we have a platform triggered flow that only continues under certain conditions. Now, in order to actually do something useful with this flow, we will see how to get & interpret the event details. Check out the next step.

3 - Get Event Details using the flow action

In this step, we will use the flow action Get Event Details to get the data related to the event. This data can be used in further flow elements. For example, on file upload, you may want to create a custom object record to save some file metadata such as the file name, extension, external storage URL, date of upload etc...

In order to use this action, simply insert the flow action named "Get Event Details" and configure it as shown below. The action takes a single input which is the triggering record (i.e. the CloudFiles Event Object we discussed in the above step). You don't need anything else to use this action.

Document image


The output to this flow action can further be used in the flow. As shown below, this action outputs a variable which has output for each type of CloudFiles Event. Depending on the event type, you can check the individual outputs and use them in your processes. E.g. you can intercept the file uploaded event to capture the file name and the folder uploaded event to capture the folder name.

Document image


For a full reference to this flow action, refer to the Get Event Details flow action. For a full reference to all the event types and the related outputs, refer to All Event Types.