Transforming Data with Flow

Here's the scenario: we have various forms on our website (e.g. Contact Us, Subscribe, etc.). When forms are submitted, unauthenticated webhooks are sent as POST requests to a receiving Apex REST Resource Class. Once received, a resulting Form Submission (Form_Submission__c) is created. Our end goal is to figure out how we can relate Form Submissions to Leads.

While we can tackle this in many ways, we're planning to use Flow's Transform element to instill simplicity, flexibility, and maintainability within the finished product.

Developing The Flow

Let's design a Record-Triggered Flow that uses the Transform element to fulfill our requirement. We'll need to be conscious of the fact that some of the website forms omit key information that would result in errors when creating Leads. For example, the Subscribe form only asks for an email address.

  • Navigate to Setup > Flows and click "New Flow"
  • Choose Record-Triggered Flow and click "Create"

Here are the Flow Elements in scope:

  • Start Criteria
  • Get Existing Lead (Get Records)
  • Received Existing Lead? (Decision)
  • Transform Form Submission to Lead (Transform)
  • Assign "Web" Lead Source (Assignment)
  • Create Lead (Create Records)
  • Relate Form Submission to Lead (Update Records)
Record-Triggered Flow

To start, let's ensure that the incoming Form Submission's Email is populated (this value is used downstream in the Flow):

Start Criteria

Next, we'll query any existing Lead with a matching Email:

Get Existing Lead (Get Records)

Check to see if a Lead was received:

Received Existing Lead? (Decision)

If an existing Lead was not found, we'll transform the Form Submission (Form_Submission__c) into a Lead:

Transform Form Submission to Lead (Transform)

Within the Transform element, we need to handle the aforementioned scenario where required fields on a Lead may be excluded from the Webhook's payload.

For the Company and Last Name fields, we'll leverage formulas to handle null values. To add a formula, click on an existing mapping and choose the formula button:

Company (Formula)

Last Name (Formula)

We also need to supplement the Lead data with the appropriate Lead Source value. This is one shortcoming with the current Transform element: it doesn't allow us to populate unmapped fields with formulas.

Assign "Web" Lead Source (Assignment)

Create the Lead:

Create Lead (Create Records)

Lastly, we will relate the Form Submission to the appropriate Lead. To do this, we're going to use a formula resource:

Relate Form Submission to Lead (Update Records)

Here's the formula used within formulaLeadId:

formulaLeadId (Formula)

We're able to rapidly transform data in an aesthetically pleasing manner between flow resources with the Transform element. Anyone that's used ETL software in the past will feel at home with the user interface!

Share

References